/src/mozilla-central/layout/generic/nsFrame.cpp
Line | Count | Source (jump to first uncovered line) |
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/. */ |
6 | | |
7 | | /* base class of all rendering objects */ |
8 | | |
9 | | #include "nsFrame.h" |
10 | | |
11 | | #include <stdarg.h> |
12 | | #include <algorithm> |
13 | | |
14 | | #include "gfx2DGlue.h" |
15 | | #include "gfxUtils.h" |
16 | | #include "mozilla/Attributes.h" |
17 | | #include "mozilla/ComputedStyle.h" |
18 | | #include "mozilla/DebugOnly.h" |
19 | | #include "mozilla/dom/ElementInlines.h" |
20 | | #include "mozilla/dom/Selection.h" |
21 | | #include "mozilla/gfx/2D.h" |
22 | | #include "mozilla/gfx/PathHelpers.h" |
23 | | #include "mozilla/Sprintf.h" |
24 | | |
25 | | #include "nsCOMPtr.h" |
26 | | #include "nsFlexContainerFrame.h" |
27 | | #include "nsFrameList.h" |
28 | | #include "nsPlaceholderFrame.h" |
29 | | #include "nsPluginFrame.h" |
30 | | #include "nsIBaseWindow.h" |
31 | | #include "nsIContent.h" |
32 | | #include "nsIContentInlines.h" |
33 | | #include "nsContentUtils.h" |
34 | | #include "nsCSSFrameConstructor.h" |
35 | | #include "nsCSSProps.h" |
36 | | #include "nsCSSPseudoElements.h" |
37 | | #include "nsCSSRendering.h" |
38 | | #include "nsAtom.h" |
39 | | #include "nsString.h" |
40 | | #include "nsReadableUtils.h" |
41 | | #include "nsTableWrapperFrame.h" |
42 | | #include "nsView.h" |
43 | | #include "nsViewManager.h" |
44 | | #include "nsIScrollableFrame.h" |
45 | | #include "nsPresContext.h" |
46 | | #include "nsStyleConsts.h" |
47 | | #include "nsIPresShell.h" |
48 | | #include "mozilla/Logging.h" |
49 | | #include "mozilla/Sprintf.h" |
50 | | #include "nsLayoutUtils.h" |
51 | | #include "LayoutLogging.h" |
52 | | #include "mozilla/RestyleManager.h" |
53 | | #include "nsInlineFrame.h" |
54 | | #include "nsFrameSelection.h" |
55 | | #include "nsGkAtoms.h" |
56 | | #include "nsCSSAnonBoxes.h" |
57 | | #include "nsCSSClipPathInstance.h" |
58 | | |
59 | | #include "nsFrameTraversal.h" |
60 | | #include "nsRange.h" |
61 | | #include "nsITextControlFrame.h" |
62 | | #include "nsNameSpaceManager.h" |
63 | | #include "nsIPercentBSizeObserver.h" |
64 | | #include "nsStyleStructInlines.h" |
65 | | #include "FrameLayerBuilder.h" |
66 | | #include "ImageLayers.h" |
67 | | |
68 | | #include "nsBidiPresUtils.h" |
69 | | #include "RubyUtils.h" |
70 | | #include "nsAnimationManager.h" |
71 | | |
72 | | // For triple-click pref |
73 | | #include "imgIContainer.h" |
74 | | #include "imgIRequest.h" |
75 | | #include "nsError.h" |
76 | | #include "nsContainerFrame.h" |
77 | | #include "nsBoxLayoutState.h" |
78 | | #include "nsBlockFrame.h" |
79 | | #include "nsDisplayList.h" |
80 | | #include "nsSVGIntegrationUtils.h" |
81 | | #include "SVGObserverUtils.h" |
82 | | #include "nsSVGMaskFrame.h" |
83 | | #include "nsChangeHint.h" |
84 | | #include "nsDeckFrame.h" |
85 | | #include "nsSubDocumentFrame.h" |
86 | | #include "SVGTextFrame.h" |
87 | | #include "RetainedDisplayListBuilder.h" |
88 | | |
89 | | #include "gfxContext.h" |
90 | | #include "gfxPrefs.h" |
91 | | #include "nsAbsoluteContainingBlock.h" |
92 | | #include "StickyScrollContainer.h" |
93 | | #include "nsFontInflationData.h" |
94 | | #include "nsRegion.h" |
95 | | #include "nsIFrameInlines.h" |
96 | | #include "nsStyleChangeList.h" |
97 | | #include "nsWindowSizes.h" |
98 | | |
99 | | #include "mozilla/AsyncEventDispatcher.h" |
100 | | #include "mozilla/EffectCompositor.h" |
101 | | #include "mozilla/EffectSet.h" |
102 | | #include "mozilla/EventListenerManager.h" |
103 | | #include "mozilla/EventStateManager.h" |
104 | | #include "mozilla/EventStates.h" |
105 | | #include "mozilla/Preferences.h" |
106 | | #include "mozilla/LookAndFeel.h" |
107 | | #include "mozilla/MouseEvents.h" |
108 | | #include "mozilla/ServoStyleSet.h" |
109 | | #include "mozilla/ServoStyleSetInlines.h" |
110 | | #include "mozilla/css/ImageLoader.h" |
111 | | #include "mozilla/dom/TouchEvent.h" |
112 | | #include "mozilla/gfx/Tools.h" |
113 | | #include "mozilla/layers/WebRenderUserData.h" |
114 | | #include "nsPrintfCString.h" |
115 | | #include "ActiveLayerTracker.h" |
116 | | |
117 | | #include "nsITheme.h" |
118 | | #include "nsStyleConsts.h" |
119 | | |
120 | | #include "ImageLoader.h" |
121 | | |
122 | | using namespace mozilla; |
123 | | using namespace mozilla::css; |
124 | | using namespace mozilla::dom; |
125 | | using namespace mozilla::gfx; |
126 | | using namespace mozilla::layers; |
127 | | using namespace mozilla::layout; |
128 | | typedef nsAbsoluteContainingBlock::AbsPosReflowFlags AbsPosReflowFlags; |
129 | | |
130 | | const mozilla::LayoutFrameType nsIFrame::sLayoutFrameTypes[ |
131 | | #define FRAME_ID(...) 1 + |
132 | | #define ABSTRACT_FRAME_ID(...) |
133 | | #include "nsFrameIdList.h" |
134 | | #undef FRAME_ID |
135 | | #undef ABSTRACT_FRAME_ID |
136 | | 0] = { |
137 | | #define FRAME_ID(class_, type_, ...) mozilla::LayoutFrameType:: type_, |
138 | | #define ABSTRACT_FRAME_ID(...) |
139 | | #include "nsFrameIdList.h" |
140 | | #undef FRAME_ID |
141 | | #undef ABSTRACT_FRAME_ID |
142 | | }; |
143 | | |
144 | | const nsIFrame::FrameClassBits nsIFrame::sFrameClassBits[ |
145 | | #define FRAME_ID(...) 1 + |
146 | | #define ABSTRACT_FRAME_ID(...) |
147 | | #include "nsFrameIdList.h" |
148 | | #undef FRAME_ID |
149 | | #undef ABSTRACT_FRAME_ID |
150 | | 0] = { |
151 | | #define Leaf eFrameClassBitsLeaf |
152 | | #define NotLeaf eFrameClassBitsNone |
153 | | #define DynamicLeaf eFrameClassBitsDynamicLeaf |
154 | | #define FRAME_ID(class_, type_, leaf_, ...) leaf_, |
155 | | #define ABSTRACT_FRAME_ID(...) |
156 | | #include "nsFrameIdList.h" |
157 | | #undef Leaf |
158 | | #undef NotLeaf |
159 | | #undef DynamicLeaf |
160 | | #undef FRAME_ID |
161 | | #undef ABSTRACT_FRAME_ID |
162 | | }; |
163 | | |
164 | | // Struct containing cached metrics for box-wrapped frames. |
165 | | struct nsBoxLayoutMetrics |
166 | | { |
167 | | nsSize mPrefSize; |
168 | | nsSize mMinSize; |
169 | | nsSize mMaxSize; |
170 | | |
171 | | nsSize mBlockMinSize; |
172 | | nsSize mBlockPrefSize; |
173 | | nscoord mBlockAscent; |
174 | | |
175 | | nscoord mFlex; |
176 | | nscoord mAscent; |
177 | | |
178 | | nsSize mLastSize; |
179 | | }; |
180 | | |
181 | | struct nsContentAndOffset |
182 | | { |
183 | | nsIContent* mContent; |
184 | | int32_t mOffset; |
185 | | }; |
186 | | |
187 | | // Some Misc #defines |
188 | | #define SELECTION_DEBUG 0 |
189 | | #define FORCE_SELECTION_UPDATE 1 |
190 | | #define CALC_DEBUG 0 |
191 | | |
192 | | // This is faster than nsBidiPresUtils::IsFrameInParagraphDirection, |
193 | | // because it uses the frame pointer passed in without drilling down to |
194 | | // the leaf frame. |
195 | | static bool |
196 | | IsReversedDirectionFrame(nsIFrame* aFrame) |
197 | 0 | { |
198 | 0 | FrameBidiData bidiData = aFrame->GetBidiData(); |
199 | 0 | return !IS_SAME_DIRECTION(bidiData.embeddingLevel, bidiData.baseLevel); |
200 | 0 | } |
201 | | |
202 | | #include "nsILineIterator.h" |
203 | | #include "prenv.h" |
204 | | |
205 | | NS_DECLARE_FRAME_PROPERTY_DELETABLE(BoxMetricsProperty, nsBoxLayoutMetrics) |
206 | | |
207 | | static void |
208 | | InitBoxMetrics(nsIFrame* aFrame, bool aClear) |
209 | 0 | { |
210 | 0 | if (aClear) { |
211 | 0 | aFrame->DeleteProperty(BoxMetricsProperty()); |
212 | 0 | } |
213 | 0 |
|
214 | 0 | nsBoxLayoutMetrics* metrics = new nsBoxLayoutMetrics(); |
215 | 0 | aFrame->SetProperty(BoxMetricsProperty(), metrics); |
216 | 0 |
|
217 | 0 | static_cast<nsFrame*>(aFrame)->nsFrame::MarkIntrinsicISizesDirty(); |
218 | 0 | metrics->mBlockAscent = 0; |
219 | 0 | metrics->mLastSize.SizeTo(0, 0); |
220 | 0 | } |
221 | | |
222 | | static bool |
223 | | IsXULBoxWrapped(const nsIFrame* aFrame) |
224 | 0 | { |
225 | 0 | return aFrame->GetParent() && |
226 | 0 | aFrame->GetParent()->IsXULBoxFrame() && |
227 | 0 | !aFrame->IsXULBoxFrame(); |
228 | 0 | } |
229 | | |
230 | | void |
231 | | nsReflowStatus::UpdateTruncated(const ReflowInput& aReflowInput, |
232 | | const ReflowOutput& aMetrics) |
233 | 0 | { |
234 | 0 | const WritingMode containerWM = aMetrics.GetWritingMode(); |
235 | 0 | if (aReflowInput.GetWritingMode().IsOrthogonalTo(containerWM)) { |
236 | 0 | // Orthogonal flows are always reflowed with an unconstrained dimension, |
237 | 0 | // so should never end up truncated (see ReflowInput::Init()). |
238 | 0 | mTruncated = false; |
239 | 0 | } else if (aReflowInput.AvailableBSize() != NS_UNCONSTRAINEDSIZE && |
240 | 0 | aReflowInput.AvailableBSize() < aMetrics.BSize(containerWM) && |
241 | 0 | !aReflowInput.mFlags.mIsTopOfPage) { |
242 | 0 | mTruncated = true; |
243 | 0 | } else { |
244 | 0 | mTruncated = false; |
245 | 0 | } |
246 | 0 | } |
247 | | |
248 | | /* static */ void |
249 | | nsIFrame::DestroyAnonymousContent(nsPresContext* aPresContext, |
250 | | already_AddRefed<nsIContent>&& aContent) |
251 | 0 | { |
252 | 0 | if (nsCOMPtr<nsIContent> content = aContent) { |
253 | 0 | aPresContext->EventStateManager()->NativeAnonymousContentRemoved(content); |
254 | 0 | content->UnbindFromTree(); |
255 | 0 | } |
256 | 0 | } |
257 | | |
258 | | // Formerly the nsIFrameDebug interface |
259 | | |
260 | | std::ostream& operator<<(std::ostream& aStream, |
261 | | const nsReflowStatus& aStatus) |
262 | 0 | { |
263 | 0 | char complete = 'Y'; |
264 | 0 | if (aStatus.IsIncomplete()) { |
265 | 0 | complete = 'N'; |
266 | 0 | } else if (aStatus.IsOverflowIncomplete()) { |
267 | 0 | complete = 'O'; |
268 | 0 | } |
269 | 0 |
|
270 | 0 | char brk = 'N'; |
271 | 0 | if (aStatus.IsInlineBreakBefore()) { |
272 | 0 | brk = 'B'; |
273 | 0 | } else if (aStatus.IsInlineBreakAfter()) { |
274 | 0 | brk = 'A'; |
275 | 0 | } |
276 | 0 |
|
277 | 0 | aStream << "[" |
278 | 0 | << "Complete=" << complete << "," |
279 | 0 | << "NIF=" << (aStatus.NextInFlowNeedsReflow() ? 'Y' : 'N') << "," |
280 | 0 | << "Truncated=" << (aStatus.IsTruncated() ? 'Y' : 'N') << "," |
281 | 0 | << "Break=" << brk << "," |
282 | 0 | << "FirstLetter=" << (aStatus.FirstLetterComplete() ? 'Y' : 'N') |
283 | 0 | << "]"; |
284 | 0 | return aStream; |
285 | 0 | } |
286 | | |
287 | | #ifdef DEBUG |
288 | | static bool gShowFrameBorders = false; |
289 | | |
290 | | void nsFrame::ShowFrameBorders(bool aEnable) |
291 | | { |
292 | | gShowFrameBorders = aEnable; |
293 | | } |
294 | | |
295 | | bool nsFrame::GetShowFrameBorders() |
296 | | { |
297 | | return gShowFrameBorders; |
298 | | } |
299 | | |
300 | | static bool gShowEventTargetFrameBorder = false; |
301 | | |
302 | | void nsFrame::ShowEventTargetFrameBorder(bool aEnable) |
303 | | { |
304 | | gShowEventTargetFrameBorder = aEnable; |
305 | | } |
306 | | |
307 | | bool nsFrame::GetShowEventTargetFrameBorder() |
308 | | { |
309 | | return gShowEventTargetFrameBorder; |
310 | | } |
311 | | |
312 | | /** |
313 | | * Note: the log module is created during library initialization which |
314 | | * means that you cannot perform logging before then. |
315 | | */ |
316 | | mozilla::LazyLogModule nsFrame::sFrameLogModule("frame"); |
317 | | |
318 | | #endif |
319 | | |
320 | | NS_DECLARE_FRAME_PROPERTY_DELETABLE(AbsoluteContainingBlockProperty, |
321 | | nsAbsoluteContainingBlock) |
322 | | |
323 | | bool |
324 | 0 | nsIFrame::HasAbsolutelyPositionedChildren() const { |
325 | 0 | return IsAbsoluteContainer() && GetAbsoluteContainingBlock()->HasAbsoluteFrames(); |
326 | 0 | } |
327 | | |
328 | | nsAbsoluteContainingBlock* |
329 | 0 | nsIFrame::GetAbsoluteContainingBlock() const { |
330 | 0 | NS_ASSERTION(IsAbsoluteContainer(), "The frame is not marked as an abspos container correctly"); |
331 | 0 | nsAbsoluteContainingBlock* absCB = GetProperty(AbsoluteContainingBlockProperty()); |
332 | 0 | NS_ASSERTION(absCB, "The frame is marked as an abspos container but doesn't have the property"); |
333 | 0 | return absCB; |
334 | 0 | } |
335 | | |
336 | | void |
337 | | nsIFrame::MarkAsAbsoluteContainingBlock() |
338 | 0 | { |
339 | 0 | MOZ_ASSERT(GetStateBits() & NS_FRAME_CAN_HAVE_ABSPOS_CHILDREN); |
340 | 0 | NS_ASSERTION(!GetProperty(AbsoluteContainingBlockProperty()), |
341 | 0 | "Already has an abs-pos containing block property?"); |
342 | 0 | NS_ASSERTION(!HasAnyStateBits(NS_FRAME_HAS_ABSPOS_CHILDREN), |
343 | 0 | "Already has NS_FRAME_HAS_ABSPOS_CHILDREN state bit?"); |
344 | 0 | AddStateBits(NS_FRAME_HAS_ABSPOS_CHILDREN); |
345 | 0 | SetProperty(AbsoluteContainingBlockProperty(), new nsAbsoluteContainingBlock(GetAbsoluteListID())); |
346 | 0 | } |
347 | | |
348 | | void |
349 | | nsIFrame::MarkAsNotAbsoluteContainingBlock() |
350 | 0 | { |
351 | 0 | NS_ASSERTION(!HasAbsolutelyPositionedChildren(), "Think of the children!"); |
352 | 0 | NS_ASSERTION(GetProperty(AbsoluteContainingBlockProperty()), |
353 | 0 | "Should have an abs-pos containing block property"); |
354 | 0 | NS_ASSERTION(HasAnyStateBits(NS_FRAME_HAS_ABSPOS_CHILDREN), |
355 | 0 | "Should have NS_FRAME_HAS_ABSPOS_CHILDREN state bit"); |
356 | 0 | MOZ_ASSERT(HasAnyStateBits(NS_FRAME_CAN_HAVE_ABSPOS_CHILDREN)); |
357 | 0 | RemoveStateBits(NS_FRAME_HAS_ABSPOS_CHILDREN); |
358 | 0 | DeleteProperty(AbsoluteContainingBlockProperty()); |
359 | 0 | } |
360 | | |
361 | | bool |
362 | | nsIFrame::CheckAndClearPaintedState() |
363 | 0 | { |
364 | 0 | bool result = (GetStateBits() & NS_FRAME_PAINTED_THEBES); |
365 | 0 | RemoveStateBits(NS_FRAME_PAINTED_THEBES); |
366 | 0 |
|
367 | 0 | nsIFrame::ChildListIterator lists(this); |
368 | 0 | for (; !lists.IsDone(); lists.Next()) { |
369 | 0 | nsFrameList::Enumerator childFrames(lists.CurrentList()); |
370 | 0 | for (; !childFrames.AtEnd(); childFrames.Next()) { |
371 | 0 | nsIFrame* child = childFrames.get(); |
372 | 0 | if (child->CheckAndClearPaintedState()) { |
373 | 0 | result = true; |
374 | 0 | } |
375 | 0 | } |
376 | 0 | } |
377 | 0 | return result; |
378 | 0 | } |
379 | | |
380 | | bool |
381 | | nsIFrame::CheckAndClearDisplayListState() |
382 | 0 | { |
383 | 0 | bool result = BuiltDisplayList(); |
384 | 0 | SetBuiltDisplayList(false); |
385 | 0 |
|
386 | 0 | nsIFrame::ChildListIterator lists(this); |
387 | 0 | for (; !lists.IsDone(); lists.Next()) { |
388 | 0 | nsFrameList::Enumerator childFrames(lists.CurrentList()); |
389 | 0 | for (; !childFrames.AtEnd(); childFrames.Next()) { |
390 | 0 | nsIFrame* child = childFrames.get(); |
391 | 0 | if (child->CheckAndClearDisplayListState()) { |
392 | 0 | result = true; |
393 | 0 | } |
394 | 0 | } |
395 | 0 | } |
396 | 0 | return result; |
397 | 0 | } |
398 | | |
399 | | bool |
400 | | nsIFrame::IsVisibleConsideringAncestors(uint32_t aFlags) const |
401 | 0 | { |
402 | 0 | if (!StyleVisibility()->IsVisible()) { |
403 | 0 | return false; |
404 | 0 | } |
405 | 0 | |
406 | 0 | const nsIFrame* frame = this; |
407 | 0 | while (frame) { |
408 | 0 | nsView* view = frame->GetView(); |
409 | 0 | if (view && view->GetVisibility() == nsViewVisibility_kHide) |
410 | 0 | return false; |
411 | 0 | |
412 | 0 | nsIFrame* parent = frame->GetParent(); |
413 | 0 | nsDeckFrame* deck = do_QueryFrame(parent); |
414 | 0 | if (deck) { |
415 | 0 | if (deck->GetSelectedBox() != frame) |
416 | 0 | return false; |
417 | 0 | } |
418 | 0 | |
419 | 0 | if (parent) { |
420 | 0 | frame = parent; |
421 | 0 | } else { |
422 | 0 | parent = nsLayoutUtils::GetCrossDocParentFrame(frame); |
423 | 0 | if (!parent) |
424 | 0 | break; |
425 | 0 | |
426 | 0 | if ((aFlags & nsIFrame::VISIBILITY_CROSS_CHROME_CONTENT_BOUNDARY) == 0 && |
427 | 0 | parent->PresContext()->IsChrome() && !frame->PresContext()->IsChrome()) { |
428 | 0 | break; |
429 | 0 | } |
430 | 0 | |
431 | 0 | if (!parent->StyleVisibility()->IsVisible()) |
432 | 0 | return false; |
433 | 0 | |
434 | 0 | frame = parent; |
435 | 0 | } |
436 | 0 | } |
437 | 0 |
|
438 | 0 | return true; |
439 | 0 | } |
440 | | |
441 | | void |
442 | | nsIFrame::FindCloserFrameForSelection(const nsPoint& aPoint, |
443 | | FrameWithDistance* aCurrentBestFrame) |
444 | 0 | { |
445 | 0 | if (nsLayoutUtils::PointIsCloserToRect(aPoint, mRect, |
446 | 0 | aCurrentBestFrame->mXDistance, |
447 | 0 | aCurrentBestFrame->mYDistance)) { |
448 | 0 | aCurrentBestFrame->mFrame = this; |
449 | 0 | } |
450 | 0 | } |
451 | | |
452 | | void |
453 | | nsIFrame::ContentStatesChanged(mozilla::EventStates aStates) |
454 | 0 | { |
455 | 0 | } |
456 | | |
457 | | AutoWeakFrame::AutoWeakFrame(const WeakFrame& aOther) |
458 | | : mPrev(nullptr), mFrame(nullptr) |
459 | 0 | { |
460 | 0 | Init(aOther.GetFrame()); |
461 | 0 | } |
462 | | |
463 | | void |
464 | | AutoWeakFrame::Init(nsIFrame* aFrame) |
465 | 21 | { |
466 | 21 | Clear(mFrame ? mFrame->PresContext()->GetPresShell() : nullptr); |
467 | 21 | mFrame = aFrame; |
468 | 21 | if (mFrame) { |
469 | 0 | nsIPresShell* shell = mFrame->PresContext()->GetPresShell(); |
470 | 0 | NS_WARNING_ASSERTION(shell, "Null PresShell in AutoWeakFrame!"); |
471 | 0 | if (shell) { |
472 | 0 | shell->AddAutoWeakFrame(this); |
473 | 0 | } else { |
474 | 0 | mFrame = nullptr; |
475 | 0 | } |
476 | 0 | } |
477 | 21 | } |
478 | | |
479 | | void |
480 | | WeakFrame::Init(nsIFrame* aFrame) |
481 | 0 | { |
482 | 0 | Clear(mFrame ? mFrame->PresContext()->GetPresShell() : nullptr); |
483 | 0 | mFrame = aFrame; |
484 | 0 | if (mFrame) { |
485 | 0 | nsIPresShell* shell = mFrame->PresContext()->GetPresShell(); |
486 | 0 | MOZ_ASSERT(shell, "Null PresShell in WeakFrame!"); |
487 | 0 | if (shell) { |
488 | 0 | shell->AddWeakFrame(this); |
489 | 0 | } else { |
490 | 0 | mFrame = nullptr; |
491 | 0 | } |
492 | 0 | } |
493 | 0 | } |
494 | | |
495 | | nsIFrame* |
496 | | NS_NewEmptyFrame(nsIPresShell* aPresShell, ComputedStyle* aStyle) |
497 | 0 | { |
498 | 0 | return new (aPresShell) nsFrame(aStyle); |
499 | 0 | } |
500 | | |
501 | | nsFrame::nsFrame(ComputedStyle* aStyle, ClassID aID) |
502 | | : nsBox(aID) |
503 | 0 | { |
504 | 0 | MOZ_COUNT_CTOR(nsFrame); |
505 | 0 |
|
506 | 0 | mComputedStyle = aStyle; |
507 | 0 | mWritingMode = WritingMode(mComputedStyle); |
508 | 0 | } |
509 | | |
510 | | nsFrame::~nsFrame() |
511 | 0 | { |
512 | 0 | MOZ_COUNT_DTOR(nsFrame); |
513 | 0 |
|
514 | 0 | MOZ_ASSERT(GetVisibility() != Visibility::APPROXIMATELY_VISIBLE, |
515 | 0 | "Visible nsFrame is being destroyed"); |
516 | 0 | } |
517 | | |
518 | | NS_IMPL_FRAMEARENA_HELPERS(nsFrame) |
519 | | |
520 | | // Dummy operator delete. Will never be called, but must be defined |
521 | | // to satisfy some C++ ABIs. |
522 | | void |
523 | | nsFrame::operator delete(void *, size_t) |
524 | 0 | { |
525 | 0 | MOZ_CRASH("nsFrame::operator delete should never be called"); |
526 | 0 | } |
527 | | |
528 | 0 | NS_QUERYFRAME_HEAD(nsFrame) |
529 | 0 | NS_QUERYFRAME_ENTRY(nsIFrame) |
530 | 0 | NS_QUERYFRAME_TAIL_INHERITANCE_ROOT |
531 | | |
532 | | ///////////////////////////////////////////////////////////////////////////// |
533 | | // nsIFrame |
534 | | |
535 | | static bool |
536 | | IsFontSizeInflationContainer(nsIFrame* aFrame, |
537 | | const nsStyleDisplay* aStyleDisplay) |
538 | 0 | { |
539 | 0 | /* |
540 | 0 | * Font size inflation is built around the idea that we're inflating |
541 | 0 | * the fonts for a pan-and-zoom UI so that when the user scales up a |
542 | 0 | * block or other container to fill the width of the device, the fonts |
543 | 0 | * will be readable. To do this, we need to pick what counts as a |
544 | 0 | * container. |
545 | 0 | * |
546 | 0 | * From a code perspective, the only hard requirement is that frames |
547 | 0 | * that are line participants |
548 | 0 | * (nsIFrame::IsFrameOfType(nsIFrame::eLineParticipant)) are never |
549 | 0 | * containers, since line layout assumes that the inflation is |
550 | 0 | * consistent within a line. |
551 | 0 | * |
552 | 0 | * This is not an imposition, since we obviously want a bunch of text |
553 | 0 | * (possibly with inline elements) flowing within a block to count the |
554 | 0 | * block (or higher) as its container. |
555 | 0 | * |
556 | 0 | * We also want form controls, including the text in the anonymous |
557 | 0 | * content inside of them, to match each other and the text next to |
558 | 0 | * them, so they and their anonymous content should also not be a |
559 | 0 | * container. |
560 | 0 | * |
561 | 0 | * However, because we can't reliably compute sizes across XUL during |
562 | 0 | * reflow, any XUL frame with a XUL parent is always a container. |
563 | 0 | * |
564 | 0 | * There are contexts where it would be nice if some blocks didn't |
565 | 0 | * count as a container, so that, for example, an indented quotation |
566 | 0 | * didn't end up with a smaller font size. However, it's hard to |
567 | 0 | * distinguish these situations where we really do want the indented |
568 | 0 | * thing to count as a container, so we don't try, and blocks are |
569 | 0 | * always containers. |
570 | 0 | */ |
571 | 0 |
|
572 | 0 | // The root frame should always be an inflation container. |
573 | 0 | if (!aFrame->GetParent()) { |
574 | 0 | return true; |
575 | 0 | } |
576 | 0 | |
577 | 0 | nsIContent *content = aFrame->GetContent(); |
578 | 0 | LayoutFrameType frameType = aFrame->Type(); |
579 | 0 | bool isInline = (aFrame->GetDisplay() == StyleDisplay::Inline || |
580 | 0 | RubyUtils::IsRubyBox(frameType) || |
581 | 0 | (aFrame->IsFloating() && |
582 | 0 | frameType == LayoutFrameType::Letter) || |
583 | 0 | // Given multiple frames for the same node, only the |
584 | 0 | // outer one should be considered a container. |
585 | 0 | // (Important, e.g., for nsSelectsAreaFrame.) |
586 | 0 | (aFrame->GetParent()->GetContent() == content) || |
587 | 0 | (content && (content->IsAnyOfHTMLElements(nsGkAtoms::option, |
588 | 0 | nsGkAtoms::optgroup, |
589 | 0 | nsGkAtoms::select) || |
590 | 0 | content->IsInNativeAnonymousSubtree()))) && |
591 | 0 | !(aFrame->IsXULBoxFrame() && aFrame->GetParent()->IsXULBoxFrame()); |
592 | 0 | NS_ASSERTION(!aFrame->IsFrameOfType(nsIFrame::eLineParticipant) || |
593 | 0 | isInline || |
594 | 0 | // br frames and mathml frames report being line |
595 | 0 | // participants even when their position or display is |
596 | 0 | // set |
597 | 0 | aFrame->IsBrFrame() || |
598 | 0 | aFrame->IsFrameOfType(nsIFrame::eMathML), |
599 | 0 | "line participants must not be containers"); |
600 | 0 | NS_ASSERTION(!aFrame->IsBulletFrame() || isInline, |
601 | 0 | "bullets should not be containers"); |
602 | 0 | return !isInline; |
603 | 0 | } |
604 | | |
605 | | void |
606 | | nsFrame::Init(nsIContent* aContent, |
607 | | nsContainerFrame* aParent, |
608 | | nsIFrame* aPrevInFlow) |
609 | 0 | { |
610 | 0 | MOZ_ASSERT(nsQueryFrame::FrameIID(mClass) == GetFrameId()); |
611 | 0 | MOZ_ASSERT(!mContent, "Double-initing a frame?"); |
612 | 0 | NS_ASSERTION(IsFrameOfType(eDEBUGAllFrames) && |
613 | 0 | !IsFrameOfType(eDEBUGNoFrames), |
614 | 0 | "IsFrameOfType implementation that doesn't call base class"); |
615 | 0 |
|
616 | 0 | mContent = aContent; |
617 | 0 | mParent = aParent; |
618 | 0 | MOZ_DIAGNOSTIC_ASSERT(!mParent || PresShell() == mParent->PresShell()); |
619 | 0 |
|
620 | 0 | if (aPrevInFlow) { |
621 | 0 | mWritingMode = aPrevInFlow->GetWritingMode(); |
622 | 0 |
|
623 | 0 | // Make sure the general flags bits are the same |
624 | 0 | nsFrameState state = aPrevInFlow->GetStateBits(); |
625 | 0 |
|
626 | 0 | // Make bits that are currently off (see constructor) the same: |
627 | 0 | AddStateBits(state & (NS_FRAME_INDEPENDENT_SELECTION | |
628 | 0 | NS_FRAME_PART_OF_IBSPLIT | |
629 | 0 | NS_FRAME_MAY_BE_TRANSFORMED | |
630 | 0 | NS_FRAME_CAN_HAVE_ABSPOS_CHILDREN)); |
631 | 0 | } else { |
632 | 0 | PresContext()->ConstructedFrame(); |
633 | 0 | } |
634 | 0 | if (GetParent()) { |
635 | 0 | nsFrameState state = GetParent()->GetStateBits(); |
636 | 0 |
|
637 | 0 | // Make bits that are currently off (see constructor) the same: |
638 | 0 | AddStateBits(state & (NS_FRAME_INDEPENDENT_SELECTION | |
639 | 0 | NS_FRAME_GENERATED_CONTENT | |
640 | 0 | NS_FRAME_IS_SVG_TEXT | |
641 | 0 | NS_FRAME_IN_POPUP | |
642 | 0 | NS_FRAME_IS_NONDISPLAY)); |
643 | 0 |
|
644 | 0 | if (HasAnyStateBits(NS_FRAME_IN_POPUP) && TrackingVisibility()) { |
645 | 0 | // Assume all frames in popups are visible. |
646 | 0 | IncApproximateVisibleCount(); |
647 | 0 | } |
648 | 0 | } |
649 | 0 | if (aPrevInFlow) { |
650 | 0 | mMayHaveOpacityAnimation = aPrevInFlow->MayHaveOpacityAnimation(); |
651 | 0 | mMayHaveTransformAnimation = aPrevInFlow->MayHaveTransformAnimation(); |
652 | 0 | } else if (mContent) { |
653 | 0 | EffectSet* effectSet = EffectSet::GetEffectSet(this); |
654 | 0 | if (effectSet) { |
655 | 0 | mMayHaveOpacityAnimation = effectSet->MayHaveOpacityAnimation(); |
656 | 0 | mMayHaveTransformAnimation = effectSet->MayHaveTransformAnimation(); |
657 | 0 | } |
658 | 0 | } |
659 | 0 |
|
660 | 0 | const nsStyleDisplay *disp = StyleDisplay(); |
661 | 0 | if (disp->HasTransform(this) || |
662 | 0 | (IsFrameOfType(eSupportsCSSTransforms) && |
663 | 0 | nsLayoutUtils::HasAnimationOfProperty(this, eCSSProperty_transform))) { |
664 | 0 | // The frame gets reconstructed if we toggle the -moz-transform |
665 | 0 | // property, so we can set this bit here and then ignore it. |
666 | 0 | AddStateBits(NS_FRAME_MAY_BE_TRANSFORMED); |
667 | 0 | } |
668 | 0 | if (disp->mPosition == NS_STYLE_POSITION_STICKY && |
669 | 0 | !aPrevInFlow && |
670 | 0 | !(mState & NS_FRAME_IS_NONDISPLAY)) { |
671 | 0 | // Note that we only add first continuations, but we really only |
672 | 0 | // want to add first continuation-or-ib-split-siblings. But since we |
673 | 0 | // don't yet know if we're a later part of a block-in-inline split, |
674 | 0 | // we'll just add later members of a block-in-inline split here, and |
675 | 0 | // then StickyScrollContainer will remove them later. |
676 | 0 | StickyScrollContainer* ssc = |
677 | 0 | StickyScrollContainer::GetStickyScrollContainerForFrame(this); |
678 | 0 | if (ssc) { |
679 | 0 | ssc->AddFrame(this); |
680 | 0 | } |
681 | 0 | } |
682 | 0 |
|
683 | 0 | if (nsLayoutUtils::FontSizeInflationEnabled(PresContext()) || !GetParent() |
684 | | #ifdef DEBUG |
685 | | // We have assertions that check inflation invariants even when |
686 | | // font size inflation is not enabled. |
687 | | || true |
688 | | #endif |
689 | 0 | ) { |
690 | 0 | if (IsFontSizeInflationContainer(this, disp)) { |
691 | 0 | AddStateBits(NS_FRAME_FONT_INFLATION_CONTAINER); |
692 | 0 | if (!GetParent() || |
693 | 0 | // I'd use NS_FRAME_OUT_OF_FLOW, but it's not set yet. |
694 | 0 | disp->IsFloating(this) || disp->IsAbsolutelyPositioned(this)) { |
695 | 0 | AddStateBits(NS_FRAME_FONT_INFLATION_FLOW_ROOT); |
696 | 0 | } |
697 | 0 | } |
698 | 0 | NS_ASSERTION(GetParent() || |
699 | 0 | (GetStateBits() & NS_FRAME_FONT_INFLATION_CONTAINER), |
700 | 0 | "root frame should always be a container"); |
701 | 0 | } |
702 | 0 |
|
703 | 0 | if (PresShell()->AssumeAllFramesVisible() && TrackingVisibility()) { |
704 | 0 | IncApproximateVisibleCount(); |
705 | 0 | } |
706 | 0 |
|
707 | 0 | DidSetComputedStyle(nullptr); |
708 | 0 |
|
709 | 0 | if (::IsXULBoxWrapped(this)) |
710 | 0 | ::InitBoxMetrics(this, false); |
711 | 0 |
|
712 | 0 | // For a newly created frame, we need to update this frame's visibility state. |
713 | 0 | // Usually we update the state when the frame is restyled and has a |
714 | 0 | // VisibilityChange change hint but we don't generate any change hints for |
715 | 0 | // newly created frames. |
716 | 0 | // Note: We don't need to do this for placeholders since placeholders have |
717 | 0 | // different styles so that the styles don't have visibility:hidden even if |
718 | 0 | // the parent has visibility:hidden style. |
719 | 0 | if (!IsPlaceholderFrame()) { |
720 | 0 | UpdateVisibleDescendantsState(); |
721 | 0 | } |
722 | 0 | } |
723 | | |
724 | | void |
725 | | nsFrame::DestroyFrom(nsIFrame* aDestructRoot, PostDestroyData& aPostDestroyData) |
726 | 0 | { |
727 | 0 | NS_ASSERTION(!nsContentUtils::IsSafeToRunScript(), |
728 | 0 | "destroy called on frame while scripts not blocked"); |
729 | 0 | NS_ASSERTION(!GetNextSibling() && !GetPrevSibling(), |
730 | 0 | "Frames should be removed before destruction."); |
731 | 0 | NS_ASSERTION(aDestructRoot, "Must specify destruct root"); |
732 | 0 | MOZ_ASSERT(!HasAbsolutelyPositionedChildren()); |
733 | 0 | MOZ_ASSERT(!HasAnyStateBits(NS_FRAME_PART_OF_IBSPLIT), |
734 | 0 | "NS_FRAME_PART_OF_IBSPLIT set on non-nsContainerFrame?"); |
735 | 0 |
|
736 | 0 | SVGObserverUtils::InvalidateDirectRenderingObservers(this); |
737 | 0 |
|
738 | 0 | if (StyleDisplay()->mPosition == NS_STYLE_POSITION_STICKY) { |
739 | 0 | StickyScrollContainer* ssc = |
740 | 0 | StickyScrollContainer::GetStickyScrollContainerForFrame(this); |
741 | 0 | if (ssc) { |
742 | 0 | ssc->RemoveFrame(this); |
743 | 0 | } |
744 | 0 | } |
745 | 0 |
|
746 | 0 | nsPresContext* presContext = PresContext(); |
747 | 0 | nsIPresShell* shell = presContext->GetPresShell(); |
748 | 0 | if (mState & NS_FRAME_OUT_OF_FLOW) { |
749 | 0 | nsPlaceholderFrame* placeholder = GetPlaceholderFrame(); |
750 | 0 | NS_ASSERTION(!placeholder || (aDestructRoot != this), |
751 | 0 | "Don't call Destroy() on OOFs, call Destroy() on the placeholder."); |
752 | 0 | NS_ASSERTION(!placeholder || |
753 | 0 | nsLayoutUtils::IsProperAncestorFrame(aDestructRoot, placeholder), |
754 | 0 | "Placeholder relationship should have been torn down already; " |
755 | 0 | "this might mean we have a stray placeholder in the tree."); |
756 | 0 | if (placeholder) { |
757 | 0 | placeholder->SetOutOfFlowFrame(nullptr); |
758 | 0 | } |
759 | 0 | } |
760 | 0 |
|
761 | 0 | if (IsPrimaryFrame()) { |
762 | 0 | // This needs to happen before we clear our Properties() table. |
763 | 0 | ActiveLayerTracker::TransferActivityToContent(this, mContent); |
764 | 0 | } |
765 | 0 |
|
766 | 0 | if (HasCSSAnimations() || HasCSSTransitions() || |
767 | 0 | EffectSet::GetEffectSet(this)) { |
768 | 0 | // If no new frame for this element is created by the end of the |
769 | 0 | // restyling process, stop animations and transitions for this frame |
770 | 0 | RestyleManager::AnimationsWithDestroyedFrame* adf = |
771 | 0 | presContext->RestyleManager()->GetAnimationsWithDestroyedFrame(); |
772 | 0 | // AnimationsWithDestroyedFrame only lives during the restyling process. |
773 | 0 | if (adf) { |
774 | 0 | adf->Put(mContent, mComputedStyle); |
775 | 0 | } |
776 | 0 | } |
777 | 0 |
|
778 | 0 | // Disable visibility tracking. Note that we have to do this before we clear |
779 | 0 | // frame properties and lose track of whether we were previously visible. |
780 | 0 | // XXX(seth): It'd be ideal to assert that we're already marked nonvisible |
781 | 0 | // here, but it's unfortunately tricky to guarantee in the face of things like |
782 | 0 | // frame reconstruction induced by style changes. |
783 | 0 | DisableVisibilityTracking(); |
784 | 0 |
|
785 | 0 | // Ensure that we're not in the approximately visible list anymore. |
786 | 0 | PresContext()->GetPresShell()->RemoveFrameFromApproximatelyVisibleList(this); |
787 | 0 |
|
788 | 0 | shell->NotifyDestroyingFrame(this); |
789 | 0 |
|
790 | 0 | if (mState & NS_FRAME_EXTERNAL_REFERENCE) { |
791 | 0 | shell->ClearFrameRefs(this); |
792 | 0 | } |
793 | 0 |
|
794 | 0 | nsView* view = GetView(); |
795 | 0 | if (view) { |
796 | 0 | view->SetFrame(nullptr); |
797 | 0 | view->Destroy(); |
798 | 0 | } |
799 | 0 |
|
800 | 0 | // Make sure that our deleted frame can't be returned from GetPrimaryFrame() |
801 | 0 | if (IsPrimaryFrame()) { |
802 | 0 | mContent->SetPrimaryFrame(nullptr); |
803 | 0 |
|
804 | 0 | // Pass the root of a generated content subtree (e.g. ::after/::before) to |
805 | 0 | // aPostDestroyData to unbind it after frame destruction is done. |
806 | 0 | if (HasAnyStateBits(NS_FRAME_GENERATED_CONTENT) && |
807 | 0 | mContent->IsRootOfNativeAnonymousSubtree()) { |
808 | 0 | aPostDestroyData.AddAnonymousContent(mContent.forget()); |
809 | 0 | } |
810 | 0 | } |
811 | 0 |
|
812 | 0 | // Delete all properties attached to the frame, to ensure any property |
813 | 0 | // destructors that need the frame pointer are handled properly. |
814 | 0 | DeleteAllProperties(); |
815 | 0 |
|
816 | 0 | // Must retrieve the object ID before calling destructors, so the |
817 | 0 | // vtable is still valid. |
818 | 0 | // |
819 | 0 | // Note to future tweakers: having the method that returns the |
820 | 0 | // object size call the destructor will not avoid an indirect call; |
821 | 0 | // the compiler cannot devirtualize the call to the destructor even |
822 | 0 | // if it's from a method defined in the same class. |
823 | 0 |
|
824 | 0 | nsQueryFrame::FrameIID id = GetFrameId(); |
825 | 0 | this->~nsFrame(); |
826 | 0 |
|
827 | | #ifdef DEBUG |
828 | | { |
829 | | nsIFrame* rootFrame = shell->GetRootFrame(); |
830 | | MOZ_ASSERT(rootFrame); |
831 | | if (this != rootFrame) { |
832 | | const RetainedDisplayListData* data = |
833 | | GetRetainedDisplayListData(rootFrame); |
834 | | |
835 | | const bool inModifiedList = data && |
836 | | (data->GetFlags(this) & RetainedDisplayListData::FrameFlags::Modified); |
837 | | |
838 | | MOZ_ASSERT(!inModifiedList, |
839 | | "A dtor added this frame to modified frames list!"); |
840 | | } |
841 | | } |
842 | | #endif |
843 | |
|
844 | 0 | // Now that we're totally cleaned out, we need to add ourselves to |
845 | 0 | // the presshell's recycler. |
846 | 0 | shell->FreeFrame(id, this); |
847 | 0 | } |
848 | | |
849 | | nsresult |
850 | | nsFrame::GetOffsets(int32_t &aStart, int32_t &aEnd) const |
851 | 0 | { |
852 | 0 | aStart = 0; |
853 | 0 | aEnd = 0; |
854 | 0 | return NS_OK; |
855 | 0 | } |
856 | | |
857 | | static void |
858 | | CompareLayers(const nsStyleImageLayers* aFirstLayers, |
859 | | const nsStyleImageLayers* aSecondLayers, |
860 | | const std::function<void(imgRequestProxy* aReq)>& aCallback) |
861 | 0 | { |
862 | 0 | NS_FOR_VISIBLE_IMAGE_LAYERS_BACK_TO_FRONT(i, (*aFirstLayers)) { |
863 | 0 | const nsStyleImage& image = aFirstLayers->mLayers[i].mImage; |
864 | 0 | if (image.GetType() != eStyleImageType_Image || !image.IsResolved()) { |
865 | 0 | continue; |
866 | 0 | } |
867 | 0 | |
868 | 0 | // aCallback is called when the style image in aFirstLayers is thought to |
869 | 0 | // be different with the corresponded one in aSecondLayers |
870 | 0 | if (!aSecondLayers || i >= aSecondLayers->mImageCount || |
871 | 0 | (!aSecondLayers->mLayers[i].mImage.IsResolved() || |
872 | 0 | !image.ImageDataEquals(aSecondLayers->mLayers[i].mImage))) { |
873 | 0 | if (imgRequestProxy* req = image.GetImageData()) { |
874 | 0 | aCallback(req); |
875 | 0 | } |
876 | 0 | } |
877 | 0 | } |
878 | 0 | } |
879 | | |
880 | | static void |
881 | | AddAndRemoveImageAssociations(nsFrame* aFrame, |
882 | | const nsStyleImageLayers* aOldLayers, |
883 | | const nsStyleImageLayers* aNewLayers) |
884 | 0 | { |
885 | 0 | ImageLoader* imageLoader = |
886 | 0 | aFrame->PresContext()->Document()->StyleImageLoader(); |
887 | 0 |
|
888 | 0 | // If the old context had a background-image image, or mask-image image, |
889 | 0 | // and new context does not have the same image, clear the image load |
890 | 0 | // notifier (which keeps the image loading, if it still is) for the frame. |
891 | 0 | // We want to do this conservatively because some frames paint their |
892 | 0 | // backgrounds from some other frame's style data, and we don't want |
893 | 0 | // to clear those notifiers unless we have to. (They'll be reset |
894 | 0 | // when we paint, although we could miss a notification in that |
895 | 0 | // interval.) |
896 | 0 | if (aOldLayers && aFrame->HasImageRequest()) { |
897 | 0 | CompareLayers(aOldLayers, aNewLayers, |
898 | 0 | [&imageLoader, aFrame](imgRequestProxy* aReq) |
899 | 0 | { imageLoader->DisassociateRequestFromFrame(aReq, aFrame); } |
900 | 0 | ); |
901 | 0 | } |
902 | 0 |
|
903 | 0 | CompareLayers(aNewLayers, aOldLayers, |
904 | 0 | [&imageLoader, aFrame](imgRequestProxy* aReq) |
905 | 0 | { imageLoader->AssociateRequestToFrame(aReq, aFrame, 0); } |
906 | 0 | ); |
907 | 0 | } |
908 | | |
909 | | void |
910 | | nsIFrame::AddDisplayItem(nsDisplayItem* aItem) |
911 | 0 | { |
912 | 0 | DisplayItemArray* items = GetProperty(DisplayItems()); |
913 | 0 | if (!items) { |
914 | 0 | items = new DisplayItemArray(); |
915 | 0 | AddProperty(DisplayItems(), items); |
916 | 0 | } |
917 | 0 | MOZ_DIAGNOSTIC_ASSERT(!items->Contains(aItem)); |
918 | 0 | items->AppendElement(aItem); |
919 | 0 | } |
920 | | |
921 | | bool |
922 | | nsIFrame::RemoveDisplayItem(nsDisplayItem* aItem) |
923 | 0 | { |
924 | 0 | DisplayItemArray* items = GetProperty(DisplayItems()); |
925 | 0 | if (!items) { |
926 | 0 | return false; |
927 | 0 | } |
928 | 0 | bool result = items->RemoveElement(aItem); |
929 | 0 | if (items->IsEmpty()) { |
930 | 0 | DeleteProperty(DisplayItems()); |
931 | 0 | } |
932 | 0 | return result; |
933 | 0 | } |
934 | | |
935 | | bool |
936 | | nsIFrame::HasDisplayItems() |
937 | 0 | { |
938 | 0 | DisplayItemArray* items = GetProperty(DisplayItems()); |
939 | 0 | return items != nullptr; |
940 | 0 | } |
941 | | |
942 | | bool |
943 | | nsIFrame::HasDisplayItem(nsDisplayItem* aItem) |
944 | 0 | { |
945 | 0 | DisplayItemArray* items = GetProperty(DisplayItems()); |
946 | 0 | if (!items) { |
947 | 0 | return false; |
948 | 0 | } |
949 | 0 | return items->Contains(aItem); |
950 | 0 | } |
951 | | |
952 | | void |
953 | | nsIFrame::RemoveDisplayItemDataForDeletion() |
954 | 0 | { |
955 | 0 | FrameLayerBuilder::RemoveFrameFromLayerManager(this, DisplayItemData()); |
956 | 0 | DisplayItemData().Clear(); |
957 | 0 |
|
958 | 0 | DisplayItemArray* items = RemoveProperty(DisplayItems()); |
959 | 0 | if (items) { |
960 | 0 | for (nsDisplayItem* i : *items) { |
961 | 0 | if (i->GetDependentFrame() == this && |
962 | 0 | !i->HasDeletedFrame()) { |
963 | 0 | i->Frame()->MarkNeedsDisplayItemRebuild(); |
964 | 0 | } |
965 | 0 | i->RemoveFrame(this); |
966 | 0 | } |
967 | 0 | delete items; |
968 | 0 | } |
969 | 0 |
|
970 | 0 | if (!nsLayoutUtils::AreRetainedDisplayListsEnabled()) { |
971 | 0 | // Retained display lists are disabled, no need to update |
972 | 0 | // RetainedDisplayListData. |
973 | 0 | return; |
974 | 0 | } |
975 | 0 | |
976 | 0 | const bool updateData = |
977 | 0 | IsFrameModified() || HasOverrideDirtyRegion() || MayHaveWillChangeBudget(); |
978 | 0 |
|
979 | 0 | if (!updateData) { |
980 | 0 | // No RetainedDisplayListData to update. |
981 | 0 | return; |
982 | 0 | } |
983 | 0 | |
984 | 0 | nsIFrame* rootFrame = PresShell()->GetRootFrame(); |
985 | 0 | MOZ_ASSERT(rootFrame); |
986 | 0 |
|
987 | 0 | RetainedDisplayListData* data = GetOrSetRetainedDisplayListData(rootFrame); |
988 | 0 |
|
989 | 0 | if (MayHaveWillChangeBudget()) { |
990 | 0 | // Keep the frame in list, so it can be removed from the will-change budget. |
991 | 0 | data->Flags(this) = RetainedDisplayListData::FrameFlags::HadWillChange; |
992 | 0 | return; |
993 | 0 | } |
994 | 0 | |
995 | 0 | if (IsFrameModified() || HasOverrideDirtyRegion()) { |
996 | 0 | // Remove deleted frames from RetainedDisplayListData. |
997 | 0 | DebugOnly<bool> removed = data->Remove(this); |
998 | 0 | MOZ_ASSERT(removed, |
999 | 0 | "Frame had flags set, but it was not found in DisplayListData!"); |
1000 | 0 | } |
1001 | 0 | } |
1002 | | |
1003 | | void |
1004 | | nsIFrame::MarkNeedsDisplayItemRebuild() |
1005 | 0 | { |
1006 | 0 | if (!nsLayoutUtils::AreRetainedDisplayListsEnabled() || |
1007 | 0 | IsFrameModified() || |
1008 | 0 | HasAnyStateBits(NS_FRAME_IN_POPUP)) { |
1009 | 0 | // Skip frames that are already marked modified. |
1010 | 0 | return; |
1011 | 0 | } |
1012 | 0 | |
1013 | 0 | if (Type() == LayoutFrameType::Placeholder) { |
1014 | 0 | nsIFrame* oof = static_cast<nsPlaceholderFrame*>(this)->GetOutOfFlowFrame(); |
1015 | 0 | if (oof) { |
1016 | 0 | oof->MarkNeedsDisplayItemRebuild(); |
1017 | 0 | } |
1018 | 0 | // Do not mark placeholder frames modified. |
1019 | 0 | return; |
1020 | 0 | } |
1021 | 0 |
|
1022 | 0 | if (!nsLayoutUtils::DisplayRootHasRetainedDisplayListBuilder(this)) { |
1023 | 0 | return; |
1024 | 0 | } |
1025 | 0 | |
1026 | 0 | nsIFrame* rootFrame = PresShell()->GetRootFrame(); |
1027 | 0 | MOZ_ASSERT(rootFrame); |
1028 | 0 |
|
1029 | 0 | if (rootFrame->IsFrameModified()) { |
1030 | 0 | return; |
1031 | 0 | } |
1032 | 0 | |
1033 | 0 | RetainedDisplayListData* data = GetOrSetRetainedDisplayListData(rootFrame); |
1034 | 0 | data->Flags(this) |= RetainedDisplayListData::FrameFlags::Modified; |
1035 | 0 | SetFrameIsModified(true); |
1036 | 0 |
|
1037 | 0 | MOZ_ASSERT( |
1038 | 0 | PresContext()->LayoutPhaseCount(eLayoutPhase_DisplayListBuilding) == 0); |
1039 | 0 |
|
1040 | 0 | // Hopefully this is cheap, but we could use a frame state bit to note |
1041 | 0 | // the presence of dependencies to speed it up. |
1042 | 0 | DisplayItemArray* items = GetProperty(DisplayItems()); |
1043 | 0 | if (items) { |
1044 | 0 | for (nsDisplayItem* i : *items) { |
1045 | 0 | if (i->GetDependentFrame() == this && |
1046 | 0 | !i->HasDeletedFrame()) { |
1047 | 0 | i->Frame()->MarkNeedsDisplayItemRebuild(); |
1048 | 0 | } |
1049 | 0 | } |
1050 | 0 | } |
1051 | 0 | } |
1052 | | |
1053 | | // Subclass hook for style post processing |
1054 | | /* virtual */ void |
1055 | | nsFrame::DidSetComputedStyle(ComputedStyle* aOldComputedStyle) |
1056 | 0 | { |
1057 | 0 | if (nsSVGUtils::IsInSVGTextSubtree(this)) { |
1058 | 0 | SVGTextFrame* svgTextFrame = static_cast<SVGTextFrame*>( |
1059 | 0 | nsLayoutUtils::GetClosestFrameOfType(this, LayoutFrameType::SVGText)); |
1060 | 0 | nsIFrame* anonBlock = svgTextFrame->PrincipalChildList().FirstChild(); |
1061 | 0 | // Just as in SVGTextFrame::DidSetComputedStyle, we need to ensure that |
1062 | 0 | // any non-display SVGTextFrames get reflowed when a child text frame |
1063 | 0 | // gets new style. |
1064 | 0 | // |
1065 | 0 | // Note that we must check NS_FRAME_FIRST_REFLOW on our SVGTextFrame's |
1066 | 0 | // anonymous block frame rather than our self, since NS_FRAME_FIRST_REFLOW |
1067 | 0 | // may be set on us if we're a new frame that has been inserted after the |
1068 | 0 | // document's first reflow. (In which case this DidSetComputedStyle call may |
1069 | 0 | // be happening under frame construction under a Reflow() call.) |
1070 | 0 | if (anonBlock && !(anonBlock->GetStateBits() & NS_FRAME_FIRST_REFLOW) && |
1071 | 0 | (svgTextFrame->GetStateBits() & NS_FRAME_IS_NONDISPLAY) && |
1072 | 0 | !(svgTextFrame->GetStateBits() & NS_STATE_SVG_TEXT_IN_REFLOW)) { |
1073 | 0 | svgTextFrame->ScheduleReflowSVGNonDisplayText(nsIPresShell::eStyleChange); |
1074 | 0 | } |
1075 | 0 | } |
1076 | 0 |
|
1077 | 0 | const nsStyleImageLayers *oldLayers = aOldComputedStyle ? |
1078 | 0 | &aOldComputedStyle->StyleBackground()->mImage : |
1079 | 0 | nullptr; |
1080 | 0 | const nsStyleImageLayers *newLayers = &StyleBackground()->mImage; |
1081 | 0 | AddAndRemoveImageAssociations(this, oldLayers, newLayers); |
1082 | 0 |
|
1083 | 0 | oldLayers = aOldComputedStyle ? &aOldComputedStyle->StyleSVGReset()->mMask : |
1084 | 0 | nullptr; |
1085 | 0 | newLayers = &StyleSVGReset()->mMask; |
1086 | 0 | AddAndRemoveImageAssociations(this, oldLayers, newLayers); |
1087 | 0 |
|
1088 | 0 | if (aOldComputedStyle) { |
1089 | 0 | // If we detect a change on margin, padding or border, we store the old |
1090 | 0 | // values on the frame itself between now and reflow, so if someone |
1091 | 0 | // calls GetUsed(Margin|Border|Padding)() before the next reflow, we |
1092 | 0 | // can give an accurate answer. |
1093 | 0 | // We don't want to set the property if one already exists. |
1094 | 0 | nsMargin oldValue(0, 0, 0, 0); |
1095 | 0 | nsMargin newValue(0, 0, 0, 0); |
1096 | 0 | const nsStyleMargin* oldMargin = aOldComputedStyle->PeekStyleMargin(); |
1097 | 0 | if (oldMargin && oldMargin->GetMargin(oldValue)) { |
1098 | 0 | if ((!StyleMargin()->GetMargin(newValue) || oldValue != newValue) && |
1099 | 0 | !HasProperty(UsedMarginProperty())) { |
1100 | 0 | AddProperty(UsedMarginProperty(), new nsMargin(oldValue)); |
1101 | 0 | } |
1102 | 0 | } |
1103 | 0 |
|
1104 | 0 | const nsStylePadding* oldPadding = aOldComputedStyle->PeekStylePadding(); |
1105 | 0 | if (oldPadding && oldPadding->GetPadding(oldValue)) { |
1106 | 0 | if ((!StylePadding()->GetPadding(newValue) || oldValue != newValue) && |
1107 | 0 | !HasProperty(UsedPaddingProperty())) { |
1108 | 0 | AddProperty(UsedPaddingProperty(), new nsMargin(oldValue)); |
1109 | 0 | } |
1110 | 0 | } |
1111 | 0 |
|
1112 | 0 | const nsStyleBorder* oldBorder = aOldComputedStyle->PeekStyleBorder(); |
1113 | 0 | if (oldBorder) { |
1114 | 0 | oldValue = oldBorder->GetComputedBorder(); |
1115 | 0 | newValue = StyleBorder()->GetComputedBorder(); |
1116 | 0 | if (oldValue != newValue && |
1117 | 0 | !HasProperty(UsedBorderProperty())) { |
1118 | 0 | AddProperty(UsedBorderProperty(), new nsMargin(oldValue)); |
1119 | 0 | } |
1120 | 0 | } |
1121 | 0 | } |
1122 | 0 |
|
1123 | 0 | ImageLoader* imageLoader = PresContext()->Document()->StyleImageLoader(); |
1124 | 0 | imgIRequest *oldBorderImage = aOldComputedStyle |
1125 | 0 | ? aOldComputedStyle->StyleBorder()->GetBorderImageRequest() |
1126 | 0 | : nullptr; |
1127 | 0 | imgIRequest *newBorderImage = StyleBorder()->GetBorderImageRequest(); |
1128 | 0 | // FIXME (Bug 759996): The following is no longer true. |
1129 | 0 | // For border-images, we can't be as conservative (we need to set the |
1130 | 0 | // new loaders if there has been any change) since the CalcDifference |
1131 | 0 | // call depended on the result of GetComputedBorder() and that result |
1132 | 0 | // depends on whether the image has loaded, start the image load now |
1133 | 0 | // so that we'll get notified when it completes loading and can do a |
1134 | 0 | // restyle. Otherwise, the image might finish loading from the |
1135 | 0 | // network before we start listening to its notifications, and then |
1136 | 0 | // we'll never know that it's finished loading. Likewise, we want to |
1137 | 0 | // do this for freshly-created frames to prevent a similar race if the |
1138 | 0 | // image loads between reflow (which can depend on whether the image |
1139 | 0 | // is loaded) and paint. We also don't really care about any callers who try |
1140 | 0 | // to paint borders with a different style, because they won't have the |
1141 | 0 | // correct size for the border either. |
1142 | 0 | if (oldBorderImage != newBorderImage) { |
1143 | 0 | // stop and restart the image loading/notification |
1144 | 0 | if (oldBorderImage && HasImageRequest()) { |
1145 | 0 | imageLoader->DisassociateRequestFromFrame(oldBorderImage, this); |
1146 | 0 | } |
1147 | 0 | if (newBorderImage) { |
1148 | 0 | imageLoader->AssociateRequestToFrame(newBorderImage, this, 0); |
1149 | 0 | } |
1150 | 0 | } |
1151 | 0 |
|
1152 | 0 | imgIRequest* oldShapeImage = |
1153 | 0 | aOldComputedStyle |
1154 | 0 | ? aOldComputedStyle->StyleDisplay()->mShapeOutside.GetShapeImageData() |
1155 | 0 | : nullptr; |
1156 | 0 | imgIRequest* newShapeImage = |
1157 | 0 | StyleDisplay()->mShapeOutside.GetShapeImageData(); |
1158 | 0 |
|
1159 | 0 | if (oldShapeImage != newShapeImage) { |
1160 | 0 | if (oldShapeImage && HasImageRequest()) { |
1161 | 0 | imageLoader->DisassociateRequestFromFrame(oldShapeImage, this); |
1162 | 0 | } |
1163 | 0 | if (newShapeImage) { |
1164 | 0 | imageLoader->AssociateRequestToFrame(newShapeImage, this, |
1165 | 0 | ImageLoader::REQUEST_REQUIRES_REFLOW); |
1166 | 0 | } |
1167 | 0 | } |
1168 | 0 |
|
1169 | 0 | // SVGObserverUtils::GetEffectProperties() asserts that we only invoke it with |
1170 | 0 | // the first continuation so we need to check that in advance. Continuing text |
1171 | 0 | // frame doesn't initialize its continuation pointer before reaching here for |
1172 | 0 | // the first time, so we have to exclude text frames. This doesn't affect |
1173 | 0 | // correctness because text nodes themselves shouldn't have effects applied. |
1174 | 0 | if (!IsTextFrame() && !GetPrevContinuation()) { |
1175 | 0 | // Kick off loading of external SVG resources referenced from properties if |
1176 | 0 | // any. This currently includes filter, clip-path, and mask. We don't care |
1177 | 0 | // about the return value. We only want its side effect. |
1178 | 0 | Unused << SVGObserverUtils::GetEffectProperties(this); |
1179 | 0 | } |
1180 | 0 |
|
1181 | 0 | // If the page contains markup that overrides text direction, and |
1182 | 0 | // does not contain any characters that would activate the Unicode |
1183 | 0 | // bidi algorithm, we need to call |SetBidiEnabled| on the pres |
1184 | 0 | // context before reflow starts. See bug 115921. |
1185 | 0 | if (StyleVisibility()->mDirection == NS_STYLE_DIRECTION_RTL) { |
1186 | 0 | PresContext()->SetBidiEnabled(); |
1187 | 0 | } |
1188 | 0 |
|
1189 | 0 | RemoveStateBits(NS_FRAME_SIMPLE_EVENT_REGIONS | |
1190 | 0 | NS_FRAME_SIMPLE_DISPLAYLIST); |
1191 | 0 |
|
1192 | 0 | mMayHaveRoundedCorners = true; |
1193 | 0 | } |
1194 | | |
1195 | | void |
1196 | | nsIFrame::ReparentFrameViewTo(nsViewManager* aViewManager, |
1197 | | nsView* aNewParentView, |
1198 | | nsView* aOldParentView) |
1199 | 0 | { |
1200 | 0 | if (HasView()) { |
1201 | 0 | #ifdef MOZ_XUL |
1202 | 0 | if (IsMenuPopupFrame()) { |
1203 | 0 | // This view must be parented by the root view, don't reparent it. |
1204 | 0 | return; |
1205 | 0 | } |
1206 | 0 | #endif |
1207 | 0 | nsView* view = GetView(); |
1208 | 0 | // Verify that the current parent view is what we think it is |
1209 | 0 | //nsView* parentView; |
1210 | 0 | //NS_ASSERTION(parentView == aOldParentView, "unexpected parent view"); |
1211 | 0 |
|
1212 | 0 | aViewManager->RemoveChild(view); |
1213 | 0 |
|
1214 | 0 | // The view will remember the Z-order and other attributes that have been set on it. |
1215 | 0 | nsView* insertBefore = nsLayoutUtils::FindSiblingViewFor(aNewParentView, this); |
1216 | 0 | aViewManager->InsertChild(aNewParentView, view, insertBefore, insertBefore != nullptr); |
1217 | 0 | } else if (GetStateBits() & NS_FRAME_HAS_CHILD_WITH_VIEW) { |
1218 | 0 | nsIFrame::ChildListIterator lists(this); |
1219 | 0 | for (; !lists.IsDone(); lists.Next()) { |
1220 | 0 | // Iterate the child frames, and check each child frame to see if it has |
1221 | 0 | // a view |
1222 | 0 | nsFrameList::Enumerator childFrames(lists.CurrentList()); |
1223 | 0 | for (; !childFrames.AtEnd(); childFrames.Next()) { |
1224 | 0 | childFrames.get()->ReparentFrameViewTo(aViewManager, aNewParentView, |
1225 | 0 | aOldParentView); |
1226 | 0 | } |
1227 | 0 | } |
1228 | 0 | } |
1229 | 0 | } |
1230 | | |
1231 | | void |
1232 | | nsIFrame::SyncFrameViewProperties(nsView* aView) |
1233 | 0 | { |
1234 | 0 | if (!aView) { |
1235 | 0 | aView = GetView(); |
1236 | 0 | if (!aView) { |
1237 | 0 | return; |
1238 | 0 | } |
1239 | 0 | } |
1240 | 0 | |
1241 | 0 | nsViewManager* vm = aView->GetViewManager(); |
1242 | 0 |
|
1243 | 0 | // Make sure visibility is correct. This only affects nsSubDocumentFrame. |
1244 | 0 | if (!SupportsVisibilityHidden()) { |
1245 | 0 | // See if the view should be hidden or visible |
1246 | 0 | ComputedStyle* sc = Style(); |
1247 | 0 | vm->SetViewVisibility(aView, |
1248 | 0 | sc->StyleVisibility()->IsVisible() |
1249 | 0 | ? nsViewVisibility_kShow : nsViewVisibility_kHide); |
1250 | 0 | } |
1251 | 0 |
|
1252 | 0 | int32_t zIndex = 0; |
1253 | 0 | bool autoZIndex = false; |
1254 | 0 |
|
1255 | 0 | if (IsAbsPosContainingBlock()) { |
1256 | 0 | // Make sure z-index is correct |
1257 | 0 | ComputedStyle* sc = Style(); |
1258 | 0 | const nsStylePosition* position = sc->StylePosition(); |
1259 | 0 | if (position->mZIndex.GetUnit() == eStyleUnit_Integer) { |
1260 | 0 | zIndex = position->mZIndex.GetIntValue(); |
1261 | 0 | } else if (position->mZIndex.GetUnit() == eStyleUnit_Auto) { |
1262 | 0 | autoZIndex = true; |
1263 | 0 | } |
1264 | 0 | } else { |
1265 | 0 | autoZIndex = true; |
1266 | 0 | } |
1267 | 0 |
|
1268 | 0 | vm->SetViewZIndex(aView, autoZIndex, zIndex); |
1269 | 0 | } |
1270 | | |
1271 | | void |
1272 | | nsFrame::CreateView() |
1273 | 0 | { |
1274 | 0 | MOZ_ASSERT(!HasView()); |
1275 | 0 |
|
1276 | 0 | nsView* parentView = GetParent()->GetClosestView(); |
1277 | 0 | MOZ_ASSERT(parentView, "no parent with view"); |
1278 | 0 |
|
1279 | 0 | nsViewManager* viewManager = parentView->GetViewManager(); |
1280 | 0 | MOZ_ASSERT(viewManager, "null view manager"); |
1281 | 0 |
|
1282 | 0 | nsView* view = viewManager->CreateView(GetRect(), parentView); |
1283 | 0 | SyncFrameViewProperties(view); |
1284 | 0 |
|
1285 | 0 | nsView* insertBefore = nsLayoutUtils::FindSiblingViewFor(parentView, this); |
1286 | 0 | // we insert this view 'above' the insertBefore view, unless insertBefore is null, |
1287 | 0 | // in which case we want to call with aAbove == false to insert at the beginning |
1288 | 0 | // in document order |
1289 | 0 | viewManager->InsertChild(parentView, view, insertBefore, insertBefore != nullptr); |
1290 | 0 |
|
1291 | 0 | // REVIEW: Don't create a widget for fixed-pos elements anymore. |
1292 | 0 | // ComputeRepaintRegionForCopy will calculate the right area to repaint |
1293 | 0 | // when we scroll. |
1294 | 0 | // Reparent views on any child frames (or their descendants) to this |
1295 | 0 | // view. We can just call ReparentFrameViewTo on this frame because |
1296 | 0 | // we know this frame has no view, so it will crawl the children. Also, |
1297 | 0 | // we know that any descendants with views must have 'parentView' as their |
1298 | 0 | // parent view. |
1299 | 0 | ReparentFrameViewTo(viewManager, view, parentView); |
1300 | 0 |
|
1301 | 0 | // Remember our view |
1302 | 0 | SetView(view); |
1303 | 0 |
|
1304 | 0 | NS_FRAME_LOG(NS_FRAME_TRACE_CALLS, |
1305 | 0 | ("nsFrame::CreateView: frame=%p view=%p", |
1306 | 0 | this, view)); |
1307 | 0 | } |
1308 | | |
1309 | | // MSVC fails with link error "one or more multiply defined symbols found", |
1310 | | // gcc fails with "hidden symbol `nsIFrame::kPrincipalList' isn't defined" |
1311 | | // etc if they are not defined. |
1312 | | #ifndef _MSC_VER |
1313 | | // static nsIFrame constants; initialized in the header file. |
1314 | | const nsIFrame::ChildListID nsIFrame::kPrincipalList; |
1315 | | const nsIFrame::ChildListID nsIFrame::kAbsoluteList; |
1316 | | const nsIFrame::ChildListID nsIFrame::kBulletList; |
1317 | | const nsIFrame::ChildListID nsIFrame::kCaptionList; |
1318 | | const nsIFrame::ChildListID nsIFrame::kColGroupList; |
1319 | | const nsIFrame::ChildListID nsIFrame::kExcessOverflowContainersList; |
1320 | | const nsIFrame::ChildListID nsIFrame::kFixedList; |
1321 | | const nsIFrame::ChildListID nsIFrame::kFloatList; |
1322 | | const nsIFrame::ChildListID nsIFrame::kOverflowContainersList; |
1323 | | const nsIFrame::ChildListID nsIFrame::kOverflowList; |
1324 | | const nsIFrame::ChildListID nsIFrame::kOverflowOutOfFlowList; |
1325 | | const nsIFrame::ChildListID nsIFrame::kPopupList; |
1326 | | const nsIFrame::ChildListID nsIFrame::kPushedFloatsList; |
1327 | | const nsIFrame::ChildListID nsIFrame::kSelectPopupList; |
1328 | | const nsIFrame::ChildListID nsIFrame::kNoReflowPrincipalList; |
1329 | | #endif |
1330 | | |
1331 | | /* virtual */ nsMargin |
1332 | | nsIFrame::GetUsedMargin() const |
1333 | 0 | { |
1334 | 0 | nsMargin margin(0, 0, 0, 0); |
1335 | 0 | if (((mState & NS_FRAME_FIRST_REFLOW) && |
1336 | 0 | !(mState & NS_FRAME_IN_REFLOW)) || |
1337 | 0 | nsSVGUtils::IsInSVGTextSubtree(this)) |
1338 | 0 | return margin; |
1339 | 0 | |
1340 | 0 | nsMargin *m = GetProperty(UsedMarginProperty()); |
1341 | 0 | if (m) { |
1342 | 0 | margin = *m; |
1343 | 0 | } else { |
1344 | 0 | if (!StyleMargin()->GetMargin(margin)) { |
1345 | 0 | // If we get here, our caller probably shouldn't be calling us... |
1346 | 0 | NS_ERROR("Returning bogus 0-sized margin, because this margin " |
1347 | 0 | "depends on layout & isn't cached!"); |
1348 | 0 | } |
1349 | 0 | } |
1350 | 0 | return margin; |
1351 | 0 | } |
1352 | | |
1353 | | /* virtual */ nsMargin |
1354 | | nsIFrame::GetUsedBorder() const |
1355 | 0 | { |
1356 | 0 | nsMargin border(0, 0, 0, 0); |
1357 | 0 | if (((mState & NS_FRAME_FIRST_REFLOW) && |
1358 | 0 | !(mState & NS_FRAME_IN_REFLOW)) || |
1359 | 0 | nsSVGUtils::IsInSVGTextSubtree(this)) |
1360 | 0 | return border; |
1361 | 0 | |
1362 | 0 | // Theme methods don't use const-ness. |
1363 | 0 | nsIFrame* mutable_this = const_cast<nsIFrame*>(this); |
1364 | 0 |
|
1365 | 0 | const nsStyleDisplay* disp = StyleDisplay(); |
1366 | 0 | if (mutable_this->IsThemed(disp)) { |
1367 | 0 | nsPresContext* pc = PresContext(); |
1368 | 0 | LayoutDeviceIntMargin widgetBorder = |
1369 | 0 | pc->GetTheme()->GetWidgetBorder(pc->DeviceContext(), mutable_this, |
1370 | 0 | disp->mAppearance); |
1371 | 0 | border = LayoutDevicePixel::ToAppUnits(widgetBorder, |
1372 | 0 | pc->AppUnitsPerDevPixel()); |
1373 | 0 | return border; |
1374 | 0 | } |
1375 | 0 | |
1376 | 0 | nsMargin* b = GetProperty(UsedBorderProperty()); |
1377 | 0 | if (b) { |
1378 | 0 | border = *b; |
1379 | 0 | } else { |
1380 | 0 | border = StyleBorder()->GetComputedBorder(); |
1381 | 0 | } |
1382 | 0 | return border; |
1383 | 0 | } |
1384 | | |
1385 | | /* virtual */ nsMargin |
1386 | | nsIFrame::GetUsedPadding() const |
1387 | 0 | { |
1388 | 0 | nsMargin padding(0, 0, 0, 0); |
1389 | 0 | if (((mState & NS_FRAME_FIRST_REFLOW) && |
1390 | 0 | !(mState & NS_FRAME_IN_REFLOW)) || |
1391 | 0 | nsSVGUtils::IsInSVGTextSubtree(this)) |
1392 | 0 | return padding; |
1393 | 0 | |
1394 | 0 | // Theme methods don't use const-ness. |
1395 | 0 | nsIFrame* mutable_this = const_cast<nsIFrame*>(this); |
1396 | 0 |
|
1397 | 0 | const nsStyleDisplay* disp = StyleDisplay(); |
1398 | 0 | if (mutable_this->IsThemed(disp)) { |
1399 | 0 | nsPresContext* pc = PresContext(); |
1400 | 0 | LayoutDeviceIntMargin widgetPadding; |
1401 | 0 | if (pc->GetTheme()->GetWidgetPadding(pc->DeviceContext(), mutable_this, |
1402 | 0 | disp->mAppearance, &widgetPadding)) { |
1403 | 0 | return LayoutDevicePixel::ToAppUnits(widgetPadding, |
1404 | 0 | pc->AppUnitsPerDevPixel()); |
1405 | 0 | } |
1406 | 0 | } |
1407 | 0 | |
1408 | 0 | nsMargin* p = GetProperty(UsedPaddingProperty()); |
1409 | 0 | if (p) { |
1410 | 0 | padding = *p; |
1411 | 0 | } else { |
1412 | 0 | if (!StylePadding()->GetPadding(padding)) { |
1413 | 0 | // If we get here, our caller probably shouldn't be calling us... |
1414 | 0 | NS_ERROR("Returning bogus 0-sized padding, because this padding " |
1415 | 0 | "depends on layout & isn't cached!"); |
1416 | 0 | } |
1417 | 0 | } |
1418 | 0 | return padding; |
1419 | 0 | } |
1420 | | |
1421 | | nsIFrame::Sides |
1422 | | nsIFrame::GetSkipSides(const ReflowInput* aReflowInput) const |
1423 | 0 | { |
1424 | 0 | if (MOZ_UNLIKELY(StyleBorder()->mBoxDecorationBreak == |
1425 | 0 | StyleBoxDecorationBreak::Clone) && |
1426 | 0 | !(GetStateBits() & NS_FRAME_IS_OVERFLOW_CONTAINER)) { |
1427 | 0 | return Sides(); |
1428 | 0 | } |
1429 | 0 | |
1430 | 0 | // Convert the logical skip sides to physical sides using the frame's |
1431 | 0 | // writing mode |
1432 | 0 | WritingMode writingMode = GetWritingMode(); |
1433 | 0 | LogicalSides logicalSkip = GetLogicalSkipSides(aReflowInput); |
1434 | 0 | Sides skip; |
1435 | 0 |
|
1436 | 0 | if (logicalSkip.BStart()) { |
1437 | 0 | if (writingMode.IsVertical()) { |
1438 | 0 | skip |= writingMode.IsVerticalLR() ? eSideBitsLeft : eSideBitsRight; |
1439 | 0 | } else { |
1440 | 0 | skip |= eSideBitsTop; |
1441 | 0 | } |
1442 | 0 | } |
1443 | 0 |
|
1444 | 0 | if (logicalSkip.BEnd()) { |
1445 | 0 | if (writingMode.IsVertical()) { |
1446 | 0 | skip |= writingMode.IsVerticalLR() ? eSideBitsRight : eSideBitsLeft; |
1447 | 0 | } else { |
1448 | 0 | skip |= eSideBitsBottom; |
1449 | 0 | } |
1450 | 0 | } |
1451 | 0 |
|
1452 | 0 | if (logicalSkip.IStart()) { |
1453 | 0 | if (writingMode.IsVertical()) { |
1454 | 0 | skip |= eSideBitsTop; |
1455 | 0 | } else { |
1456 | 0 | skip |= writingMode.IsBidiLTR() ? eSideBitsLeft : eSideBitsRight; |
1457 | 0 | } |
1458 | 0 | } |
1459 | 0 |
|
1460 | 0 | if (logicalSkip.IEnd()) { |
1461 | 0 | if (writingMode.IsVertical()) { |
1462 | 0 | skip |= eSideBitsBottom; |
1463 | 0 | } else { |
1464 | 0 | skip |= writingMode.IsBidiLTR() ? eSideBitsRight : eSideBitsLeft; |
1465 | 0 | } |
1466 | 0 | } |
1467 | 0 | return skip; |
1468 | 0 | } |
1469 | | |
1470 | | nsRect |
1471 | | nsIFrame::GetPaddingRectRelativeToSelf() const |
1472 | 0 | { |
1473 | 0 | nsMargin border(GetUsedBorder()); |
1474 | 0 | border.ApplySkipSides(GetSkipSides()); |
1475 | 0 | nsRect r(0, 0, mRect.width, mRect.height); |
1476 | 0 | r.Deflate(border); |
1477 | 0 | return r; |
1478 | 0 | } |
1479 | | |
1480 | | nsRect |
1481 | | nsIFrame::GetPaddingRect() const |
1482 | 0 | { |
1483 | 0 | return GetPaddingRectRelativeToSelf() + GetPosition(); |
1484 | 0 | } |
1485 | | |
1486 | | WritingMode |
1487 | | nsIFrame::WritingModeForLine(WritingMode aSelfWM, |
1488 | | nsIFrame* aSubFrame) const |
1489 | 0 | { |
1490 | 0 | MOZ_ASSERT(aSelfWM == GetWritingMode()); |
1491 | 0 | WritingMode writingMode = aSelfWM; |
1492 | 0 |
|
1493 | 0 | if (StyleTextReset()->mUnicodeBidi & NS_STYLE_UNICODE_BIDI_PLAINTEXT) { |
1494 | 0 | nsBidiLevel frameLevel = nsBidiPresUtils::GetFrameBaseLevel(aSubFrame); |
1495 | 0 | writingMode.SetDirectionFromBidiLevel(frameLevel); |
1496 | 0 | } |
1497 | 0 |
|
1498 | 0 | return writingMode; |
1499 | 0 | } |
1500 | | |
1501 | | nsRect |
1502 | | nsIFrame::GetMarginRectRelativeToSelf() const |
1503 | 0 | { |
1504 | 0 | nsMargin m = GetUsedMargin(); |
1505 | 0 | m.ApplySkipSides(GetSkipSides()); |
1506 | 0 | nsRect r(0, 0, mRect.width, mRect.height); |
1507 | 0 | r.Inflate(m); |
1508 | 0 | return r; |
1509 | 0 | } |
1510 | | |
1511 | | bool |
1512 | | nsIFrame::IsTransformed(const nsStyleDisplay* aStyleDisplay) const |
1513 | 0 | { |
1514 | 0 | return IsCSSTransformed(aStyleDisplay) || |
1515 | 0 | IsSVGTransformed(); |
1516 | 0 | } |
1517 | | |
1518 | | bool |
1519 | | nsIFrame::IsCSSTransformed(const nsStyleDisplay* aStyleDisplay) const |
1520 | 0 | { |
1521 | 0 | MOZ_ASSERT(aStyleDisplay == StyleDisplay()); |
1522 | 0 | return ((mState & NS_FRAME_MAY_BE_TRANSFORMED) && |
1523 | 0 | (aStyleDisplay->HasTransform(this) || |
1524 | 0 | HasAnimationOfTransform())); |
1525 | 0 | } |
1526 | | |
1527 | | bool |
1528 | | nsIFrame::HasAnimationOfTransform() const |
1529 | 0 | { |
1530 | 0 |
|
1531 | 0 | return IsPrimaryFrame() && |
1532 | 0 | nsLayoutUtils::HasAnimationOfProperty(this, eCSSProperty_transform) && |
1533 | 0 | IsFrameOfType(eSupportsCSSTransforms); |
1534 | 0 | } |
1535 | | |
1536 | | bool |
1537 | | nsIFrame::ChildrenHavePerspective(const nsStyleDisplay* aStyleDisplay) const |
1538 | 0 | { |
1539 | 0 | MOZ_ASSERT(aStyleDisplay == StyleDisplay()); |
1540 | 0 | return aStyleDisplay->HasPerspective(this); |
1541 | 0 | } |
1542 | | |
1543 | | bool |
1544 | | nsIFrame::HasOpacityInternal(float aThreshold, |
1545 | | EffectSet* aEffectSet) const |
1546 | 0 | { |
1547 | 0 | MOZ_ASSERT(0.0 <= aThreshold && aThreshold <= 1.0, "Invalid argument"); |
1548 | 0 | if (StyleEffects()->mOpacity < aThreshold || |
1549 | 0 | (StyleDisplay()->mWillChangeBitField & NS_STYLE_WILL_CHANGE_OPACITY)) { |
1550 | 0 | return true; |
1551 | 0 | } |
1552 | 0 | |
1553 | 0 | if (!mMayHaveOpacityAnimation) { |
1554 | 0 | return false; |
1555 | 0 | } |
1556 | 0 | |
1557 | 0 | EffectSet* effects = |
1558 | 0 | aEffectSet ? aEffectSet : EffectSet::GetEffectSet(this); |
1559 | 0 | if (!effects) { |
1560 | 0 | return false; |
1561 | 0 | } |
1562 | 0 | |
1563 | 0 | return ((IsPrimaryFrame() || |
1564 | 0 | nsLayoutUtils::FirstContinuationOrIBSplitSibling(this)-> |
1565 | 0 | IsPrimaryFrame()) && |
1566 | 0 | nsLayoutUtils::HasAnimationOfProperty(effects, eCSSProperty_opacity)); |
1567 | 0 | } |
1568 | | |
1569 | | bool |
1570 | | nsIFrame::IsSVGTransformed(gfx::Matrix *aOwnTransforms, |
1571 | | gfx::Matrix *aFromParentTransforms) const |
1572 | 0 | { |
1573 | 0 | return false; |
1574 | 0 | } |
1575 | | |
1576 | | bool |
1577 | | nsIFrame::Extend3DContext(const nsStyleDisplay* aStyleDisplay, mozilla::EffectSet* aEffectSet) const |
1578 | 0 | { |
1579 | 0 | if (!(mState & NS_FRAME_MAY_BE_TRANSFORMED)) { |
1580 | 0 | return false; |
1581 | 0 | } |
1582 | 0 | const nsStyleDisplay* disp = StyleDisplayWithOptionalParam(aStyleDisplay); |
1583 | 0 | if (disp->mTransformStyle != NS_STYLE_TRANSFORM_STYLE_PRESERVE_3D || |
1584 | 0 | !IsFrameOfType(nsIFrame::eSupportsCSSTransforms)) { |
1585 | 0 | return false; |
1586 | 0 | } |
1587 | 0 | |
1588 | 0 | // If we're all scroll frame, then all descendants will be clipped, so we can't preserve 3d. |
1589 | 0 | if (IsScrollFrame()) { |
1590 | 0 | return false; |
1591 | 0 | } |
1592 | 0 | |
1593 | 0 | if (HasOpacity(aEffectSet)) { |
1594 | 0 | return false; |
1595 | 0 | } |
1596 | 0 | |
1597 | 0 | const nsStyleEffects* effects = StyleEffects(); |
1598 | 0 | return !nsFrame::ShouldApplyOverflowClipping(this, disp) && |
1599 | 0 | !GetClipPropClipRect(disp, effects, GetSize()) && |
1600 | 0 | !nsSVGIntegrationUtils::UsingEffectsForFrame(this); |
1601 | 0 | } |
1602 | | |
1603 | | bool |
1604 | | nsIFrame::Combines3DTransformWithAncestors(const nsStyleDisplay* aStyleDisplay) const |
1605 | 0 | { |
1606 | 0 | MOZ_ASSERT(aStyleDisplay == StyleDisplay()); |
1607 | 0 | nsIFrame* parent = GetClosestFlattenedTreeAncestorPrimaryFrame(); |
1608 | 0 | if (!parent || !parent->Extend3DContext()) { |
1609 | 0 | return false; |
1610 | 0 | } |
1611 | 0 | return IsCSSTransformed(aStyleDisplay) || |
1612 | 0 | BackfaceIsHidden(aStyleDisplay); |
1613 | 0 | } |
1614 | | |
1615 | | bool |
1616 | | nsIFrame::In3DContextAndBackfaceIsHidden() const |
1617 | 0 | { |
1618 | 0 | // While both tests fail most of the time, test BackfaceIsHidden() |
1619 | 0 | // first since it's likely to fail faster. |
1620 | 0 | const nsStyleDisplay* disp = StyleDisplay(); |
1621 | 0 | return BackfaceIsHidden(disp) && |
1622 | 0 | Combines3DTransformWithAncestors(disp); |
1623 | 0 | } |
1624 | | |
1625 | | bool |
1626 | | nsIFrame::HasPerspective(const nsStyleDisplay* aStyleDisplay) const |
1627 | 0 | { |
1628 | 0 | MOZ_ASSERT(aStyleDisplay == StyleDisplay()); |
1629 | 0 | if (!IsTransformed(aStyleDisplay)) { |
1630 | 0 | return false; |
1631 | 0 | } |
1632 | 0 | nsIFrame* containingBlock = GetContainingBlock(SKIP_SCROLLED_FRAME, aStyleDisplay); |
1633 | 0 | if (!containingBlock) { |
1634 | 0 | return false; |
1635 | 0 | } |
1636 | 0 | return containingBlock->ChildrenHavePerspective(); |
1637 | 0 | } |
1638 | | |
1639 | | nsRect |
1640 | | nsIFrame::GetContentRectRelativeToSelf() const |
1641 | 0 | { |
1642 | 0 | nsMargin bp(GetUsedBorderAndPadding()); |
1643 | 0 | bp.ApplySkipSides(GetSkipSides()); |
1644 | 0 | nsRect r(0, 0, mRect.width, mRect.height); |
1645 | 0 | r.Deflate(bp); |
1646 | 0 | return r; |
1647 | 0 | } |
1648 | | |
1649 | | nsRect |
1650 | | nsIFrame::GetContentRect() const |
1651 | 0 | { |
1652 | 0 | return GetContentRectRelativeToSelf() + GetPosition(); |
1653 | 0 | } |
1654 | | |
1655 | | bool |
1656 | | nsIFrame::ComputeBorderRadii(const nsStyleCorners& aBorderRadius, |
1657 | | const nsSize& aFrameSize, |
1658 | | const nsSize& aBorderArea, |
1659 | | Sides aSkipSides, |
1660 | | nscoord aRadii[8]) |
1661 | 0 | { |
1662 | 0 | // Percentages are relative to whichever side they're on. |
1663 | 0 | NS_FOR_CSS_HALF_CORNERS(i) { |
1664 | 0 | const nsStyleCoord c = aBorderRadius.Get(i); |
1665 | 0 | nscoord axis = |
1666 | 0 | HalfCornerIsX(i) ? aFrameSize.width : aFrameSize.height; |
1667 | 0 |
|
1668 | 0 | if (c.IsCoordPercentCalcUnit()) { |
1669 | 0 | aRadii[i] = c.ComputeCoordPercentCalc(axis); |
1670 | 0 | if (aRadii[i] < 0) { |
1671 | 0 | // clamp calc() |
1672 | 0 | aRadii[i] = 0; |
1673 | 0 | } |
1674 | 0 | } else { |
1675 | 0 | MOZ_ASSERT_UNREACHABLE("ComputeBorderRadii: bad unit"); |
1676 | 0 | aRadii[i] = 0; |
1677 | 0 | } |
1678 | 0 | } |
1679 | 0 |
|
1680 | 0 | if (aSkipSides.Top()) { |
1681 | 0 | aRadii[eCornerTopLeftX] = 0; |
1682 | 0 | aRadii[eCornerTopLeftY] = 0; |
1683 | 0 | aRadii[eCornerTopRightX] = 0; |
1684 | 0 | aRadii[eCornerTopRightY] = 0; |
1685 | 0 | } |
1686 | 0 |
|
1687 | 0 | if (aSkipSides.Right()) { |
1688 | 0 | aRadii[eCornerTopRightX] = 0; |
1689 | 0 | aRadii[eCornerTopRightY] = 0; |
1690 | 0 | aRadii[eCornerBottomRightX] = 0; |
1691 | 0 | aRadii[eCornerBottomRightY] = 0; |
1692 | 0 | } |
1693 | 0 |
|
1694 | 0 | if (aSkipSides.Bottom()) { |
1695 | 0 | aRadii[eCornerBottomRightX] = 0; |
1696 | 0 | aRadii[eCornerBottomRightY] = 0; |
1697 | 0 | aRadii[eCornerBottomLeftX] = 0; |
1698 | 0 | aRadii[eCornerBottomLeftY] = 0; |
1699 | 0 | } |
1700 | 0 |
|
1701 | 0 | if (aSkipSides.Left()) { |
1702 | 0 | aRadii[eCornerBottomLeftX] = 0; |
1703 | 0 | aRadii[eCornerBottomLeftY] = 0; |
1704 | 0 | aRadii[eCornerTopLeftX] = 0; |
1705 | 0 | aRadii[eCornerTopLeftY] = 0; |
1706 | 0 | } |
1707 | 0 |
|
1708 | 0 | // css3-background specifies this algorithm for reducing |
1709 | 0 | // corner radii when they are too big. |
1710 | 0 | bool haveRadius = false; |
1711 | 0 | double ratio = 1.0f; |
1712 | 0 | NS_FOR_CSS_SIDES(side) { |
1713 | 0 | uint32_t hc1 = SideToHalfCorner(side, false, true); |
1714 | 0 | uint32_t hc2 = SideToHalfCorner(side, true, true); |
1715 | 0 | nscoord length = |
1716 | 0 | SideIsVertical(side) ? aBorderArea.height : aBorderArea.width; |
1717 | 0 | nscoord sum = aRadii[hc1] + aRadii[hc2]; |
1718 | 0 | if (sum) |
1719 | 0 | haveRadius = true; |
1720 | 0 |
|
1721 | 0 | // avoid floating point division in the normal case |
1722 | 0 | if (length < sum) |
1723 | 0 | ratio = std::min(ratio, double(length)/sum); |
1724 | 0 | } |
1725 | 0 | if (ratio < 1.0) { |
1726 | 0 | NS_FOR_CSS_HALF_CORNERS(corner) { |
1727 | 0 | aRadii[corner] *= ratio; |
1728 | 0 | } |
1729 | 0 | } |
1730 | 0 |
|
1731 | 0 | return haveRadius; |
1732 | 0 | } |
1733 | | |
1734 | | /* static */ void |
1735 | | nsIFrame::InsetBorderRadii(nscoord aRadii[8], const nsMargin &aOffsets) |
1736 | 0 | { |
1737 | 0 | NS_FOR_CSS_SIDES(side) { |
1738 | 0 | nscoord offset = aOffsets.Side(side); |
1739 | 0 | uint32_t hc1 = SideToHalfCorner(side, false, false); |
1740 | 0 | uint32_t hc2 = SideToHalfCorner(side, true, false); |
1741 | 0 | aRadii[hc1] = std::max(0, aRadii[hc1] - offset); |
1742 | 0 | aRadii[hc2] = std::max(0, aRadii[hc2] - offset); |
1743 | 0 | } |
1744 | 0 | } |
1745 | | |
1746 | | /* static */ void |
1747 | | nsIFrame::OutsetBorderRadii(nscoord aRadii[8], const nsMargin &aOffsets) |
1748 | 0 | { |
1749 | 0 | auto AdjustOffset = [] (const uint32_t aRadius, const nscoord aOffset) { |
1750 | 0 | // Implement the cubic formula to adjust offset when aOffset > 0 and |
1751 | 0 | // aRadius / aOffset < 1. |
1752 | 0 | // https://drafts.csswg.org/css-shapes/#valdef-shape-box-margin-box |
1753 | 0 | if (aOffset > 0) { |
1754 | 0 | const double ratio = aRadius / double(aOffset); |
1755 | 0 | if (ratio < 1.0) { |
1756 | 0 | return nscoord(aOffset * (1.0 + std::pow(ratio - 1, 3))); |
1757 | 0 | } |
1758 | 0 | } |
1759 | 0 | return aOffset; |
1760 | 0 | }; |
1761 | 0 |
|
1762 | 0 | NS_FOR_CSS_SIDES(side) { |
1763 | 0 | const nscoord offset = aOffsets.Side(side); |
1764 | 0 | const uint32_t hc1 = SideToHalfCorner(side, false, false); |
1765 | 0 | const uint32_t hc2 = SideToHalfCorner(side, true, false); |
1766 | 0 | if (aRadii[hc1] > 0) { |
1767 | 0 | const nscoord offset1 = AdjustOffset(aRadii[hc1], offset); |
1768 | 0 | aRadii[hc1] = std::max(0, aRadii[hc1] + offset1); |
1769 | 0 | } |
1770 | 0 | if (aRadii[hc2] > 0) { |
1771 | 0 | const nscoord offset2 = AdjustOffset(aRadii[hc2], offset); |
1772 | 0 | aRadii[hc2] = std::max(0, aRadii[hc2] + offset2); |
1773 | 0 | } |
1774 | 0 | } |
1775 | 0 | } |
1776 | | |
1777 | | /* virtual */ bool |
1778 | | nsIFrame::GetBorderRadii(const nsSize& aFrameSize, const nsSize& aBorderArea, |
1779 | | Sides aSkipSides, nscoord aRadii[8]) const |
1780 | 0 | { |
1781 | 0 | if (!mMayHaveRoundedCorners) { |
1782 | 0 | memset(aRadii, 0, sizeof(nscoord) * 8); |
1783 | 0 | return false; |
1784 | 0 | } |
1785 | 0 | |
1786 | 0 | if (IsThemed()) { |
1787 | 0 | // When we're themed, the native theme code draws the border and |
1788 | 0 | // background, and therefore it doesn't make sense to tell other |
1789 | 0 | // code that's interested in border-radius that we have any radii. |
1790 | 0 | // |
1791 | 0 | // In an ideal world, we might have a way for the them to tell us an |
1792 | 0 | // border radius, but since we don't, we're better off assuming |
1793 | 0 | // zero. |
1794 | 0 | NS_FOR_CSS_HALF_CORNERS(corner) { |
1795 | 0 | aRadii[corner] = 0; |
1796 | 0 | } |
1797 | 0 | return false; |
1798 | 0 | } |
1799 | 0 |
|
1800 | 0 | const_cast<nsIFrame*>(this)->mMayHaveRoundedCorners = |
1801 | 0 | ComputeBorderRadii(StyleBorder()->mBorderRadius, |
1802 | 0 | aFrameSize, aBorderArea, |
1803 | 0 | aSkipSides, aRadii); |
1804 | 0 | return mMayHaveRoundedCorners; |
1805 | 0 | } |
1806 | | |
1807 | | bool |
1808 | | nsIFrame::GetBorderRadii(nscoord aRadii[8]) const |
1809 | 0 | { |
1810 | 0 | nsSize sz = GetSize(); |
1811 | 0 | return GetBorderRadii(sz, sz, GetSkipSides(), aRadii); |
1812 | 0 | } |
1813 | | |
1814 | | bool |
1815 | | nsIFrame::GetMarginBoxBorderRadii(nscoord aRadii[8]) const |
1816 | 0 | { |
1817 | 0 | return GetBoxBorderRadii(aRadii, GetUsedMargin(), true); |
1818 | 0 | } |
1819 | | |
1820 | | bool |
1821 | | nsIFrame::GetPaddingBoxBorderRadii(nscoord aRadii[8]) const |
1822 | 0 | { |
1823 | 0 | return GetBoxBorderRadii(aRadii, GetUsedBorder(), false); |
1824 | 0 | } |
1825 | | |
1826 | | bool |
1827 | | nsIFrame::GetContentBoxBorderRadii(nscoord aRadii[8]) const |
1828 | 0 | { |
1829 | 0 | return GetBoxBorderRadii(aRadii, GetUsedBorderAndPadding(), false); |
1830 | 0 | } |
1831 | | |
1832 | | bool |
1833 | | nsIFrame::GetBoxBorderRadii(nscoord aRadii[8], nsMargin aOffset, bool aIsOutset) const |
1834 | 0 | { |
1835 | 0 | if (!GetBorderRadii(aRadii)) |
1836 | 0 | return false; |
1837 | 0 | if (aIsOutset) { |
1838 | 0 | OutsetBorderRadii(aRadii, aOffset); |
1839 | 0 | } else { |
1840 | 0 | InsetBorderRadii(aRadii, aOffset); |
1841 | 0 | } |
1842 | 0 | NS_FOR_CSS_HALF_CORNERS(corner) { |
1843 | 0 | if (aRadii[corner]) |
1844 | 0 | return true; |
1845 | 0 | } |
1846 | 0 | return false; |
1847 | 0 | } |
1848 | | |
1849 | | bool |
1850 | | nsIFrame::GetShapeBoxBorderRadii(nscoord aRadii[8]) const |
1851 | 0 | { |
1852 | 0 | switch (StyleDisplay()->mShapeOutside.GetReferenceBox()) { |
1853 | 0 | case StyleGeometryBox::NoBox: |
1854 | 0 | return false; |
1855 | 0 | case StyleGeometryBox::ContentBox: |
1856 | 0 | return GetContentBoxBorderRadii(aRadii); |
1857 | 0 | case StyleGeometryBox::PaddingBox: |
1858 | 0 | return GetPaddingBoxBorderRadii(aRadii); |
1859 | 0 | case StyleGeometryBox::BorderBox: |
1860 | 0 | return GetBorderRadii(aRadii); |
1861 | 0 | case StyleGeometryBox::MarginBox: |
1862 | 0 | return GetMarginBoxBorderRadii(aRadii); |
1863 | 0 | default: |
1864 | 0 | MOZ_ASSERT_UNREACHABLE("Unexpected box value"); |
1865 | 0 | return false; |
1866 | 0 | } |
1867 | 0 | } |
1868 | | |
1869 | | ComputedStyle* |
1870 | | nsFrame::GetAdditionalComputedStyle(int32_t aIndex) const |
1871 | 0 | { |
1872 | 0 | MOZ_ASSERT(aIndex >= 0, "invalid index number"); |
1873 | 0 | return nullptr; |
1874 | 0 | } |
1875 | | |
1876 | | void |
1877 | | nsFrame::SetAdditionalComputedStyle(int32_t aIndex, |
1878 | | ComputedStyle* aComputedStyle) |
1879 | 0 | { |
1880 | 0 | MOZ_ASSERT(aIndex >= 0, "invalid index number"); |
1881 | 0 | } |
1882 | | |
1883 | | nscoord |
1884 | | nsFrame::GetLogicalBaseline(WritingMode aWritingMode) const |
1885 | 0 | { |
1886 | 0 | NS_ASSERTION(!NS_SUBTREE_DIRTY(this), |
1887 | 0 | "frame must not be dirty"); |
1888 | 0 | // Baseline for inverted line content is the top (block-start) margin edge, |
1889 | 0 | // as the frame is in effect "flipped" for alignment purposes. |
1890 | 0 | if (aWritingMode.IsLineInverted()) { |
1891 | 0 | return -GetLogicalUsedMargin(aWritingMode).BStart(aWritingMode); |
1892 | 0 | } |
1893 | 0 | // Otherwise, the bottom margin edge, per CSS2.1's definition of the |
1894 | 0 | // 'baseline' value of 'vertical-align'. |
1895 | 0 | return BSize(aWritingMode) + |
1896 | 0 | GetLogicalUsedMargin(aWritingMode).BEnd(aWritingMode); |
1897 | 0 | } |
1898 | | |
1899 | | const nsFrameList& |
1900 | | nsFrame::GetChildList(ChildListID aListID) const |
1901 | 0 | { |
1902 | 0 | if (IsAbsoluteContainer() && |
1903 | 0 | aListID == GetAbsoluteListID()) { |
1904 | 0 | return GetAbsoluteContainingBlock()->GetChildList(); |
1905 | 0 | } else { |
1906 | 0 | return nsFrameList::EmptyList(); |
1907 | 0 | } |
1908 | 0 | } |
1909 | | |
1910 | | void |
1911 | | nsFrame::GetChildLists(nsTArray<ChildList>* aLists) const |
1912 | 0 | { |
1913 | 0 | if (IsAbsoluteContainer()) { |
1914 | 0 | nsFrameList absoluteList = GetAbsoluteContainingBlock()->GetChildList(); |
1915 | 0 | absoluteList.AppendIfNonempty(aLists, GetAbsoluteListID()); |
1916 | 0 | } |
1917 | 0 | } |
1918 | | |
1919 | | void |
1920 | | nsIFrame::GetCrossDocChildLists(nsTArray<ChildList>* aLists) |
1921 | 0 | { |
1922 | 0 | nsSubDocumentFrame* subdocumentFrame = do_QueryFrame(this); |
1923 | 0 | if (subdocumentFrame) { |
1924 | 0 | // Descend into the subdocument |
1925 | 0 | nsIFrame* root = subdocumentFrame->GetSubdocumentRootFrame(); |
1926 | 0 | if (root) { |
1927 | 0 | aLists->AppendElement(nsIFrame::ChildList( |
1928 | 0 | nsFrameList(root, nsLayoutUtils::GetLastSibling(root)), |
1929 | 0 | nsIFrame::kPrincipalList)); |
1930 | 0 | } |
1931 | 0 | } |
1932 | 0 |
|
1933 | 0 | GetChildLists(aLists); |
1934 | 0 | } |
1935 | | |
1936 | | Visibility |
1937 | | nsIFrame::GetVisibility() const |
1938 | 0 | { |
1939 | 0 | if (!(GetStateBits() & NS_FRAME_VISIBILITY_IS_TRACKED)) { |
1940 | 0 | return Visibility::UNTRACKED; |
1941 | 0 | } |
1942 | 0 | |
1943 | 0 | bool isSet = false; |
1944 | 0 | uint32_t visibleCount = GetProperty(VisibilityStateProperty(), &isSet); |
1945 | 0 |
|
1946 | 0 | MOZ_ASSERT(isSet, "Should have a VisibilityStateProperty value " |
1947 | 0 | "if NS_FRAME_VISIBILITY_IS_TRACKED is set"); |
1948 | 0 |
|
1949 | 0 | return visibleCount > 0 |
1950 | 0 | ? Visibility::APPROXIMATELY_VISIBLE |
1951 | 0 | : Visibility::APPROXIMATELY_NONVISIBLE; |
1952 | 0 | } |
1953 | | |
1954 | | void |
1955 | | nsIFrame::UpdateVisibilitySynchronously() |
1956 | 0 | { |
1957 | 0 | nsIPresShell* presShell = PresShell(); |
1958 | 0 | if (!presShell) { |
1959 | 0 | return; |
1960 | 0 | } |
1961 | 0 | |
1962 | 0 | if (presShell->AssumeAllFramesVisible()) { |
1963 | 0 | presShell->EnsureFrameInApproximatelyVisibleList(this); |
1964 | 0 | return; |
1965 | 0 | } |
1966 | 0 | |
1967 | 0 | bool visible = StyleVisibility()->IsVisible(); |
1968 | 0 | nsIFrame* f = GetParent(); |
1969 | 0 | nsRect rect = GetRectRelativeToSelf(); |
1970 | 0 | nsIFrame* rectFrame = this; |
1971 | 0 | while (f && visible) { |
1972 | 0 | nsIScrollableFrame* sf = do_QueryFrame(f); |
1973 | 0 | if (sf) { |
1974 | 0 | nsRect transformedRect = |
1975 | 0 | nsLayoutUtils::TransformFrameRectToAncestor(rectFrame, rect, f); |
1976 | 0 | if (!sf->IsRectNearlyVisible(transformedRect)) { |
1977 | 0 | visible = false; |
1978 | 0 | break; |
1979 | 0 | } |
1980 | 0 | |
1981 | 0 | // In this code we're trying to synchronously update *approximate* |
1982 | 0 | // visibility. (In the future we may update precise visibility here as |
1983 | 0 | // well, which is why the method name does not contain 'approximate'.) The |
1984 | 0 | // IsRectNearlyVisible() check above tells us that the rect we're checking |
1985 | 0 | // is approximately visible within the scrollframe, but we still need to |
1986 | 0 | // ensure that, even if it was scrolled into view, it'd be visible when we |
1987 | 0 | // consider the rest of the document. To do that, we move transformedRect |
1988 | 0 | // to be contained in the scrollport as best we can (it might not fit) to |
1989 | 0 | // pretend that it was scrolled into view. |
1990 | 0 | rect = transformedRect.MoveInsideAndClamp(sf->GetScrollPortRect()); |
1991 | 0 | rectFrame = f; |
1992 | 0 | } |
1993 | 0 | nsIFrame* parent = f->GetParent(); |
1994 | 0 | if (!parent) { |
1995 | 0 | parent = nsLayoutUtils::GetCrossDocParentFrame(f); |
1996 | 0 | if (parent && parent->PresContext()->IsChrome()) { |
1997 | 0 | break; |
1998 | 0 | } |
1999 | 0 | } |
2000 | 0 | f = parent; |
2001 | 0 | } |
2002 | 0 |
|
2003 | 0 | if (visible) { |
2004 | 0 | presShell->EnsureFrameInApproximatelyVisibleList(this); |
2005 | 0 | } else { |
2006 | 0 | presShell->RemoveFrameFromApproximatelyVisibleList(this); |
2007 | 0 | } |
2008 | 0 | } |
2009 | | |
2010 | | void |
2011 | | nsIFrame::EnableVisibilityTracking() |
2012 | 0 | { |
2013 | 0 | if (GetStateBits() & NS_FRAME_VISIBILITY_IS_TRACKED) { |
2014 | 0 | return; // Nothing to do. |
2015 | 0 | } |
2016 | 0 | |
2017 | 0 | MOZ_ASSERT(!HasProperty(VisibilityStateProperty()), |
2018 | 0 | "Shouldn't have a VisibilityStateProperty value " |
2019 | 0 | "if NS_FRAME_VISIBILITY_IS_TRACKED is not set"); |
2020 | 0 |
|
2021 | 0 | // Add the state bit so we know to track visibility for this frame, and |
2022 | 0 | // initialize the frame property. |
2023 | 0 | AddStateBits(NS_FRAME_VISIBILITY_IS_TRACKED); |
2024 | 0 | SetProperty(VisibilityStateProperty(), 0); |
2025 | 0 |
|
2026 | 0 | nsIPresShell* presShell = PresShell(); |
2027 | 0 | if (!presShell) { |
2028 | 0 | return; |
2029 | 0 | } |
2030 | 0 | |
2031 | 0 | // Schedule a visibility update. This method will virtually always be called |
2032 | 0 | // when layout has changed anyway, so it's very unlikely that any additional |
2033 | 0 | // visibility updates will be triggered by this, but this way we guarantee |
2034 | 0 | // that if this frame is currently visible we'll eventually find out. |
2035 | 0 | presShell->ScheduleApproximateFrameVisibilityUpdateSoon(); |
2036 | 0 | } |
2037 | | |
2038 | | void |
2039 | | nsIFrame::DisableVisibilityTracking() |
2040 | 0 | { |
2041 | 0 | if (!(GetStateBits() & NS_FRAME_VISIBILITY_IS_TRACKED)) { |
2042 | 0 | return; // Nothing to do. |
2043 | 0 | } |
2044 | 0 | |
2045 | 0 | bool isSet = false; |
2046 | 0 | uint32_t visibleCount = RemoveProperty(VisibilityStateProperty(), &isSet); |
2047 | 0 |
|
2048 | 0 | MOZ_ASSERT(isSet, "Should have a VisibilityStateProperty value " |
2049 | 0 | "if NS_FRAME_VISIBILITY_IS_TRACKED is set"); |
2050 | 0 |
|
2051 | 0 | RemoveStateBits(NS_FRAME_VISIBILITY_IS_TRACKED); |
2052 | 0 |
|
2053 | 0 | if (visibleCount == 0) { |
2054 | 0 | return; // We were nonvisible. |
2055 | 0 | } |
2056 | 0 | |
2057 | 0 | // We were visible, so send an OnVisibilityChange() notification. |
2058 | 0 | OnVisibilityChange(Visibility::APPROXIMATELY_NONVISIBLE); |
2059 | 0 | } |
2060 | | |
2061 | | void |
2062 | | nsIFrame::DecApproximateVisibleCount(const Maybe<OnNonvisible>& aNonvisibleAction |
2063 | | /* = Nothing() */) |
2064 | 0 | { |
2065 | 0 | MOZ_ASSERT(GetStateBits() & NS_FRAME_VISIBILITY_IS_TRACKED); |
2066 | 0 |
|
2067 | 0 | bool isSet = false; |
2068 | 0 | uint32_t visibleCount = GetProperty(VisibilityStateProperty(), &isSet); |
2069 | 0 |
|
2070 | 0 | MOZ_ASSERT(isSet, "Should have a VisibilityStateProperty value " |
2071 | 0 | "if NS_FRAME_VISIBILITY_IS_TRACKED is set"); |
2072 | 0 | MOZ_ASSERT(visibleCount > 0, "Frame is already nonvisible and we're " |
2073 | 0 | "decrementing its visible count?"); |
2074 | 0 |
|
2075 | 0 | visibleCount--; |
2076 | 0 | SetProperty(VisibilityStateProperty(), visibleCount); |
2077 | 0 | if (visibleCount > 0) { |
2078 | 0 | return; |
2079 | 0 | } |
2080 | 0 | |
2081 | 0 | // We just became nonvisible, so send an OnVisibilityChange() notification. |
2082 | 0 | OnVisibilityChange(Visibility::APPROXIMATELY_NONVISIBLE, aNonvisibleAction); |
2083 | 0 | } |
2084 | | |
2085 | | void |
2086 | | nsIFrame::IncApproximateVisibleCount() |
2087 | 0 | { |
2088 | 0 | MOZ_ASSERT(GetStateBits() & NS_FRAME_VISIBILITY_IS_TRACKED); |
2089 | 0 |
|
2090 | 0 | bool isSet = false; |
2091 | 0 | uint32_t visibleCount = GetProperty(VisibilityStateProperty(), &isSet); |
2092 | 0 |
|
2093 | 0 | MOZ_ASSERT(isSet, "Should have a VisibilityStateProperty value " |
2094 | 0 | "if NS_FRAME_VISIBILITY_IS_TRACKED is set"); |
2095 | 0 |
|
2096 | 0 | visibleCount++; |
2097 | 0 | SetProperty(VisibilityStateProperty(), visibleCount); |
2098 | 0 | if (visibleCount > 1) { |
2099 | 0 | return; |
2100 | 0 | } |
2101 | 0 | |
2102 | 0 | // We just became visible, so send an OnVisibilityChange() notification. |
2103 | 0 | OnVisibilityChange(Visibility::APPROXIMATELY_VISIBLE); |
2104 | 0 | } |
2105 | | |
2106 | | void |
2107 | | nsIFrame::OnVisibilityChange(Visibility aNewVisibility, |
2108 | | const Maybe<OnNonvisible>& aNonvisibleAction |
2109 | | /* = Nothing() */) |
2110 | 0 | { |
2111 | 0 | // XXX(seth): In bug 1218990 we'll implement visibility tracking for CSS |
2112 | 0 | // images here. |
2113 | 0 | } |
2114 | | |
2115 | | static nsIFrame* |
2116 | | GetActiveSelectionFrame(nsPresContext* aPresContext, nsIFrame* aFrame) |
2117 | 0 | { |
2118 | 0 | nsIContent* capturingContent = nsIPresShell::GetCapturingContent(); |
2119 | 0 | if (capturingContent) { |
2120 | 0 | nsIFrame* activeFrame = aPresContext->GetPrimaryFrameFor(capturingContent); |
2121 | 0 | return activeFrame ? activeFrame : aFrame; |
2122 | 0 | } |
2123 | 0 |
|
2124 | 0 | return aFrame; |
2125 | 0 | } |
2126 | | |
2127 | | int16_t |
2128 | | nsFrame::DisplaySelection(nsPresContext* aPresContext, bool isOkToTurnOn) |
2129 | 0 | { |
2130 | 0 | int16_t selType = nsISelectionController::SELECTION_OFF; |
2131 | 0 |
|
2132 | 0 | nsCOMPtr<nsISelectionController> selCon; |
2133 | 0 | nsresult result = GetSelectionController(aPresContext, getter_AddRefs(selCon)); |
2134 | 0 | if (NS_SUCCEEDED(result) && selCon) { |
2135 | 0 | result = selCon->GetDisplaySelection(&selType); |
2136 | 0 | if (NS_SUCCEEDED(result) && (selType != nsISelectionController::SELECTION_OFF)) { |
2137 | 0 | // Check whether style allows selection. |
2138 | 0 | if (!IsSelectable(nullptr)) { |
2139 | 0 | selType = nsISelectionController::SELECTION_OFF; |
2140 | 0 | isOkToTurnOn = false; |
2141 | 0 | } |
2142 | 0 | } |
2143 | 0 | if (isOkToTurnOn && (selType == nsISelectionController::SELECTION_OFF)) { |
2144 | 0 | selCon->SetDisplaySelection(nsISelectionController::SELECTION_ON); |
2145 | 0 | selType = nsISelectionController::SELECTION_ON; |
2146 | 0 | } |
2147 | 0 | } |
2148 | 0 | return selType; |
2149 | 0 | } |
2150 | | |
2151 | | class nsDisplaySelectionOverlay : public nsDisplayItem { |
2152 | | public: |
2153 | | nsDisplaySelectionOverlay(nsDisplayListBuilder* aBuilder, |
2154 | | nsFrame* aFrame, int16_t aSelectionValue) |
2155 | 0 | : nsDisplayItem(aBuilder, aFrame), mSelectionValue(aSelectionValue) { |
2156 | 0 | MOZ_COUNT_CTOR(nsDisplaySelectionOverlay); |
2157 | 0 | } |
2158 | | #ifdef NS_BUILD_REFCNT_LOGGING |
2159 | | virtual ~nsDisplaySelectionOverlay() { |
2160 | | MOZ_COUNT_DTOR(nsDisplaySelectionOverlay); |
2161 | | } |
2162 | | #endif |
2163 | | |
2164 | | virtual void Paint(nsDisplayListBuilder* aBuilder, |
2165 | | gfxContext* aCtx) override; |
2166 | | bool CreateWebRenderCommands(mozilla::wr::DisplayListBuilder& aBuilder, |
2167 | | mozilla::wr::IpcResourceUpdateQueue& aResources, |
2168 | | const StackingContextHelper& aSc, |
2169 | | mozilla::layers::WebRenderLayerManager* aManager, |
2170 | | nsDisplayListBuilder* aDisplayListBuilder) override; |
2171 | | NS_DISPLAY_DECL_NAME("SelectionOverlay", TYPE_SELECTION_OVERLAY) |
2172 | | private: |
2173 | | Color ComputeColor() const; |
2174 | | |
2175 | | static Color ComputeColorFromSelectionStyle(ComputedStyle&); |
2176 | | static Color ApplyTransparencyIfNecessary(nscolor); |
2177 | | |
2178 | | int16_t mSelectionValue; |
2179 | | }; |
2180 | | |
2181 | | Color |
2182 | | nsDisplaySelectionOverlay::ApplyTransparencyIfNecessary(nscolor aColor) |
2183 | 0 | { |
2184 | 0 | // If it has already alpha, leave it like that. |
2185 | 0 | if (NS_GET_A(aColor) != 255) { |
2186 | 0 | return ToDeviceColor(aColor); |
2187 | 0 | } |
2188 | 0 | |
2189 | 0 | // NOTE(emilio): Blink and WebKit do something slightly different here, and |
2190 | 0 | // blend the color with white instead, both for overlays and text backgrounds. |
2191 | 0 | auto color = Color::FromABGR(aColor); |
2192 | 0 | color.a = 0.5; |
2193 | 0 | return ToDeviceColor(color); |
2194 | 0 | } |
2195 | | |
2196 | | Color |
2197 | | nsDisplaySelectionOverlay::ComputeColorFromSelectionStyle(ComputedStyle& aStyle) |
2198 | 0 | { |
2199 | 0 | return ApplyTransparencyIfNecessary( |
2200 | 0 | aStyle.GetVisitedDependentColor(&nsStyleBackground::mBackgroundColor)); |
2201 | 0 | } |
2202 | | |
2203 | | Color |
2204 | | nsDisplaySelectionOverlay::ComputeColor() const |
2205 | 0 | { |
2206 | 0 | LookAndFeel::ColorID colorID; |
2207 | 0 | if (mSelectionValue == nsISelectionController::SELECTION_ON) { |
2208 | 0 | if (RefPtr<ComputedStyle> style = mFrame->ComputeSelectionStyle()) { |
2209 | 0 | return ComputeColorFromSelectionStyle(*style); |
2210 | 0 | } |
2211 | 0 | colorID = LookAndFeel::eColorID_TextSelectBackground; |
2212 | 0 | } else if (mSelectionValue == nsISelectionController::SELECTION_ATTENTION) { |
2213 | 0 | colorID = LookAndFeel::eColorID_TextSelectBackgroundAttention; |
2214 | 0 | } else { |
2215 | 0 | colorID = LookAndFeel::eColorID_TextSelectBackgroundDisabled; |
2216 | 0 | } |
2217 | 0 |
|
2218 | 0 | return ApplyTransparencyIfNecessary( |
2219 | 0 | LookAndFeel::GetColor(colorID, NS_RGB(255, 255, 255))); |
2220 | 0 | } |
2221 | | |
2222 | | void nsDisplaySelectionOverlay::Paint(nsDisplayListBuilder* aBuilder, |
2223 | | gfxContext* aCtx) |
2224 | 0 | { |
2225 | 0 | DrawTarget& aDrawTarget = *aCtx->GetDrawTarget(); |
2226 | 0 | ColorPattern color(ComputeColor()); |
2227 | 0 |
|
2228 | 0 | nsIntRect pxRect = |
2229 | 0 | GetPaintRect().ToOutsidePixels(mFrame->PresContext()->AppUnitsPerDevPixel()); |
2230 | 0 | Rect rect(pxRect.x, pxRect.y, pxRect.width, pxRect.height); |
2231 | 0 | MaybeSnapToDevicePixels(rect, aDrawTarget, true); |
2232 | 0 |
|
2233 | 0 | aDrawTarget.FillRect(rect, color); |
2234 | 0 | } |
2235 | | |
2236 | | |
2237 | | bool |
2238 | | nsDisplaySelectionOverlay::CreateWebRenderCommands(mozilla::wr::DisplayListBuilder& aBuilder, |
2239 | | mozilla::wr::IpcResourceUpdateQueue& aResources, |
2240 | | const StackingContextHelper& aSc, |
2241 | | mozilla::layers::WebRenderLayerManager* aManager, |
2242 | | nsDisplayListBuilder* aDisplayListBuilder) |
2243 | 0 | { |
2244 | 0 | wr::LayoutRect bounds = wr::ToRoundedLayoutRect( |
2245 | 0 | LayoutDeviceRect::FromAppUnits(nsRect(ToReferenceFrame(), Frame()->GetSize()), |
2246 | 0 | mFrame->PresContext()->AppUnitsPerDevPixel())); |
2247 | 0 | aBuilder.PushRect(bounds, bounds, !BackfaceIsHidden(), |
2248 | 0 | wr::ToColorF(ComputeColor())); |
2249 | 0 | return true; |
2250 | 0 | } |
2251 | | |
2252 | | static Element* |
2253 | | FindElementAncestorForMozSelection(nsIContent* aContent) |
2254 | 0 | { |
2255 | 0 | NS_ENSURE_TRUE(aContent, nullptr); |
2256 | 0 | while (aContent && aContent->IsInNativeAnonymousSubtree()) { |
2257 | 0 | aContent = aContent->GetBindingParent(); |
2258 | 0 | } |
2259 | 0 | NS_ASSERTION(aContent, "aContent isn't in non-anonymous tree?"); |
2260 | 0 | while (aContent && !aContent->IsElement()) { |
2261 | 0 | aContent = aContent->GetParent(); |
2262 | 0 | } |
2263 | 0 | return aContent ? aContent->AsElement() : nullptr; |
2264 | 0 | } |
2265 | | |
2266 | | |
2267 | | already_AddRefed<ComputedStyle> |
2268 | | nsIFrame::ComputeSelectionStyle() const |
2269 | 0 | { |
2270 | 0 | Element* element = FindElementAncestorForMozSelection(GetContent()); |
2271 | 0 | if (!element) { |
2272 | 0 | return nullptr; |
2273 | 0 | } |
2274 | 0 | RefPtr<ComputedStyle> sc = |
2275 | 0 | PresContext()->StyleSet()->ProbePseudoElementStyle( |
2276 | 0 | *element, CSSPseudoElementType::selection, Style()); |
2277 | 0 | return sc.forget(); |
2278 | 0 | } |
2279 | | |
2280 | | /******************************************************** |
2281 | | * Refreshes each content's frame |
2282 | | *********************************************************/ |
2283 | | |
2284 | | void |
2285 | | nsFrame::DisplaySelectionOverlay(nsDisplayListBuilder* aBuilder, |
2286 | | nsDisplayList* aList, |
2287 | | uint16_t aContentType) |
2288 | 0 | { |
2289 | 0 | if (!IsSelected() || !IsVisibleForPainting(aBuilder)) { |
2290 | 0 | return; |
2291 | 0 | } |
2292 | 0 | |
2293 | 0 | int16_t displaySelection = PresShell()->GetSelectionFlags(); |
2294 | 0 | if (!(displaySelection & aContentType)) { |
2295 | 0 | return; |
2296 | 0 | } |
2297 | 0 | |
2298 | 0 | const nsFrameSelection* frameSelection = GetConstFrameSelection(); |
2299 | 0 | int16_t selectionValue = frameSelection->GetDisplaySelection(); |
2300 | 0 |
|
2301 | 0 | if (selectionValue <= nsISelectionController::SELECTION_HIDDEN) { |
2302 | 0 | return; // selection is hidden or off |
2303 | 0 | } |
2304 | 0 | |
2305 | 0 | nsIContent* newContent = mContent->GetParent(); |
2306 | 0 |
|
2307 | 0 | //check to see if we are anonymous content |
2308 | 0 | int32_t offset = 0; |
2309 | 0 | if (newContent) { |
2310 | 0 | // XXXbz there has GOT to be a better way of determining this! |
2311 | 0 | offset = newContent->ComputeIndexOf(mContent); |
2312 | 0 | } |
2313 | 0 |
|
2314 | 0 | //look up to see what selection(s) are on this frame |
2315 | 0 | UniquePtr<SelectionDetails> details = |
2316 | 0 | frameSelection->LookUpSelection(newContent, offset, 1, false); |
2317 | 0 | if (!details) |
2318 | 0 | return; |
2319 | 0 | |
2320 | 0 | bool normal = false; |
2321 | 0 | for (SelectionDetails* sd = details.get(); sd; sd = sd->mNext.get()) { |
2322 | 0 | if (sd->mSelectionType == SelectionType::eNormal) { |
2323 | 0 | normal = true; |
2324 | 0 | } |
2325 | 0 | } |
2326 | 0 |
|
2327 | 0 | if (!normal && aContentType == nsISelectionDisplay::DISPLAY_IMAGES) { |
2328 | 0 | // Don't overlay an image if it's not in the primary selection. |
2329 | 0 | return; |
2330 | 0 | } |
2331 | 0 | |
2332 | 0 | aList->AppendToTop( |
2333 | 0 | MakeDisplayItem<nsDisplaySelectionOverlay>(aBuilder, this, selectionValue)); |
2334 | 0 | } |
2335 | | |
2336 | | void |
2337 | | nsFrame::DisplayOutlineUnconditional(nsDisplayListBuilder* aBuilder, |
2338 | | const nsDisplayListSet& aLists) |
2339 | 0 | { |
2340 | 0 | if (!StyleOutline()->ShouldPaintOutline()) { |
2341 | 0 | return; |
2342 | 0 | } |
2343 | 0 | |
2344 | 0 | aLists.Outlines()->AppendToTop( |
2345 | 0 | MakeDisplayItem<nsDisplayOutline>(aBuilder, this)); |
2346 | 0 | } |
2347 | | |
2348 | | void |
2349 | | nsFrame::DisplayOutline(nsDisplayListBuilder* aBuilder, |
2350 | | const nsDisplayListSet& aLists) |
2351 | 0 | { |
2352 | 0 | if (!IsVisibleForPainting(aBuilder)) |
2353 | 0 | return; |
2354 | 0 | |
2355 | 0 | DisplayOutlineUnconditional(aBuilder, aLists); |
2356 | 0 | } |
2357 | | |
2358 | | void |
2359 | | nsIFrame::DisplayCaret(nsDisplayListBuilder* aBuilder, |
2360 | | nsDisplayList* aList) |
2361 | 0 | { |
2362 | 0 | if (!IsVisibleForPainting(aBuilder)) |
2363 | 0 | return; |
2364 | 0 | |
2365 | 0 | aList->AppendToTop(MakeDisplayItem<nsDisplayCaret>(aBuilder, this)); |
2366 | 0 | } |
2367 | | |
2368 | | nscolor |
2369 | | nsIFrame::GetCaretColorAt(int32_t aOffset) |
2370 | 0 | { |
2371 | 0 | return nsLayoutUtils::GetColor(this, &nsStyleUI::mCaretColor); |
2372 | 0 | } |
2373 | | |
2374 | | bool |
2375 | | nsFrame::DisplayBackgroundUnconditional(nsDisplayListBuilder* aBuilder, |
2376 | | const nsDisplayListSet& aLists, |
2377 | | bool aForceBackground) |
2378 | 0 | { |
2379 | 0 | // Here we don't try to detect background propagation. Frames that might |
2380 | 0 | // receive a propagated background should just set aForceBackground to |
2381 | 0 | // true. |
2382 | 0 | if (aBuilder->IsForEventDelivery() || aForceBackground || |
2383 | 0 | !StyleBackground()->IsTransparent(this) || |
2384 | 0 | StyleDisplay()->HasAppearance()) { |
2385 | 0 | return nsDisplayBackgroundImage::AppendBackgroundItemsToTop( |
2386 | 0 | aBuilder, this, GetRectRelativeToSelf(), aLists.BorderBackground()); |
2387 | 0 | } |
2388 | 0 | return false; |
2389 | 0 | } |
2390 | | |
2391 | | void |
2392 | | nsFrame::DisplayBorderBackgroundOutline(nsDisplayListBuilder* aBuilder, |
2393 | | const nsDisplayListSet& aLists, |
2394 | | bool aForceBackground) |
2395 | 0 | { |
2396 | 0 | // The visibility check belongs here since child elements have the |
2397 | 0 | // opportunity to override the visibility property and display even if |
2398 | 0 | // their parent is hidden. |
2399 | 0 | if (!IsVisibleForPainting(aBuilder)) { |
2400 | 0 | return; |
2401 | 0 | } |
2402 | 0 | |
2403 | 0 | nsCSSShadowArray* shadows = StyleEffects()->mBoxShadow; |
2404 | 0 | if (shadows && shadows->HasShadowWithInset(false)) { |
2405 | 0 | aLists.BorderBackground()->AppendToTop( |
2406 | 0 | MakeDisplayItem<nsDisplayBoxShadowOuter>(aBuilder, this)); |
2407 | 0 | } |
2408 | 0 |
|
2409 | 0 | bool bgIsThemed = DisplayBackgroundUnconditional(aBuilder, aLists, |
2410 | 0 | aForceBackground); |
2411 | 0 |
|
2412 | 0 | if (shadows && shadows->HasShadowWithInset(true)) { |
2413 | 0 | aLists.BorderBackground()->AppendToTop( |
2414 | 0 | MakeDisplayItem<nsDisplayBoxShadowInner>(aBuilder, this)); |
2415 | 0 | } |
2416 | 0 |
|
2417 | 0 | // If there's a themed background, we should not create a border item. |
2418 | 0 | // It won't be rendered. |
2419 | 0 | if (!bgIsThemed && StyleBorder()->HasBorder()) { |
2420 | 0 | aLists.BorderBackground()->AppendToTop( |
2421 | 0 | MakeDisplayItem<nsDisplayBorder>(aBuilder, this)); |
2422 | 0 | } |
2423 | 0 |
|
2424 | 0 | DisplayOutlineUnconditional(aBuilder, aLists); |
2425 | 0 | } |
2426 | | |
2427 | | inline static bool IsSVGContentWithCSSClip(const nsIFrame *aFrame) |
2428 | 0 | { |
2429 | 0 | // The CSS spec says that the 'clip' property only applies to absolutely |
2430 | 0 | // positioned elements, whereas the SVG spec says that it applies to SVG |
2431 | 0 | // elements regardless of the value of the 'position' property. Here we obey |
2432 | 0 | // the CSS spec for outer-<svg> (since that's what we generally do), but |
2433 | 0 | // obey the SVG spec for other SVG elements to which 'clip' applies. |
2434 | 0 | return (aFrame->GetStateBits() & NS_FRAME_SVG_LAYOUT) && |
2435 | 0 | aFrame->GetContent()->IsAnyOfSVGElements(nsGkAtoms::svg, |
2436 | 0 | nsGkAtoms::foreignObject); |
2437 | 0 | } |
2438 | | |
2439 | | Maybe<nsRect> |
2440 | | nsIFrame::GetClipPropClipRect(const nsStyleDisplay* aDisp, |
2441 | | const nsStyleEffects* aEffects, |
2442 | | const nsSize& aSize) const |
2443 | 0 | { |
2444 | 0 | if (!(aEffects->mClipFlags & NS_STYLE_CLIP_RECT) || |
2445 | 0 | !(aDisp->IsAbsolutelyPositioned(this) || IsSVGContentWithCSSClip(this))) { |
2446 | 0 | return Nothing(); |
2447 | 0 | } |
2448 | 0 | |
2449 | 0 | nsRect rect = aEffects->mClip; |
2450 | 0 | if (MOZ_LIKELY(StyleBorder()->mBoxDecorationBreak == |
2451 | 0 | StyleBoxDecorationBreak::Slice)) { |
2452 | 0 | // The clip applies to the joined boxes so it's relative the first |
2453 | 0 | // continuation. |
2454 | 0 | nscoord y = 0; |
2455 | 0 | for (nsIFrame* f = GetPrevContinuation(); f; f = f->GetPrevContinuation()) { |
2456 | 0 | y += f->GetRect().height; |
2457 | 0 | } |
2458 | 0 | rect.MoveBy(nsPoint(0, -y)); |
2459 | 0 | } |
2460 | 0 |
|
2461 | 0 | if (NS_STYLE_CLIP_RIGHT_AUTO & aEffects->mClipFlags) { |
2462 | 0 | rect.width = aSize.width - rect.x; |
2463 | 0 | } |
2464 | 0 | if (NS_STYLE_CLIP_BOTTOM_AUTO & aEffects->mClipFlags) { |
2465 | 0 | rect.height = aSize.height - rect.y; |
2466 | 0 | } |
2467 | 0 | return Some(rect); |
2468 | 0 | } |
2469 | | |
2470 | | /** |
2471 | | * If the CSS 'overflow' property applies to this frame, and is not |
2472 | | * handled by constructing a dedicated nsHTML/XULScrollFrame, set up clipping |
2473 | | * for that overflow in aBuilder->ClipState() to clip all containing-block |
2474 | | * descendants. |
2475 | | * |
2476 | | * Return true if clipping was applied. |
2477 | | */ |
2478 | | static bool |
2479 | | ApplyOverflowClipping(nsDisplayListBuilder* aBuilder, |
2480 | | const nsIFrame* aFrame, |
2481 | | const nsStyleDisplay* aDisp, |
2482 | | DisplayListClipState::AutoClipMultiple& aClipState) |
2483 | 0 | { |
2484 | 0 | // Only -moz-hidden-unscrollable is handled here (and 'hidden' for table |
2485 | 0 | // frames, and any non-visible value for blocks in a paginated context). |
2486 | 0 | // We allow -moz-hidden-unscrollable to apply to any kind of frame. This |
2487 | 0 | // is required by comboboxes which make their display text (an inline frame) |
2488 | 0 | // have clipping. |
2489 | 0 | if (!nsFrame::ShouldApplyOverflowClipping(aFrame, aDisp)) { |
2490 | 0 | return false; |
2491 | 0 | } |
2492 | 0 | nsRect clipRect; |
2493 | 0 | bool haveRadii = false; |
2494 | 0 | nscoord radii[8]; |
2495 | 0 | auto* disp = aFrame->StyleDisplay(); |
2496 | 0 | // Only deflate the padding if we clip to the content-box in that axis. |
2497 | 0 | auto wm = aFrame->GetWritingMode(); |
2498 | 0 | bool cbH = (wm.IsVertical() ? disp->mOverflowClipBoxBlock |
2499 | 0 | : disp->mOverflowClipBoxInline) == |
2500 | 0 | NS_STYLE_OVERFLOW_CLIP_BOX_CONTENT_BOX; |
2501 | 0 | bool cbV = (wm.IsVertical() ? disp->mOverflowClipBoxInline |
2502 | 0 | : disp->mOverflowClipBoxBlock) == |
2503 | 0 | NS_STYLE_OVERFLOW_CLIP_BOX_CONTENT_BOX; |
2504 | 0 | nsMargin bp = aFrame->GetUsedPadding(); |
2505 | 0 | if (!cbH) { |
2506 | 0 | bp.left = bp.right = nscoord(0); |
2507 | 0 | } |
2508 | 0 | if (!cbV) { |
2509 | 0 | bp.top = bp.bottom = nscoord(0); |
2510 | 0 | } |
2511 | 0 |
|
2512 | 0 | bp += aFrame->GetUsedBorder(); |
2513 | 0 | bp.ApplySkipSides(aFrame->GetSkipSides()); |
2514 | 0 | nsRect rect(nsPoint(0, 0), aFrame->GetSize()); |
2515 | 0 | rect.Deflate(bp); |
2516 | 0 | clipRect = rect + aBuilder->ToReferenceFrame(aFrame); |
2517 | 0 | haveRadii = aFrame->GetBoxBorderRadii(radii, bp, false); |
2518 | 0 | aClipState.ClipContainingBlockDescendantsExtra(clipRect, haveRadii ? radii : nullptr); |
2519 | 0 | return true; |
2520 | 0 | } |
2521 | | |
2522 | | #ifdef DEBUG |
2523 | | static void PaintDebugBorder(nsIFrame* aFrame, DrawTarget* aDrawTarget, |
2524 | | const nsRect& aDirtyRect, nsPoint aPt) |
2525 | | { |
2526 | | nsRect r(aPt, aFrame->GetSize()); |
2527 | | int32_t appUnitsPerDevPixel = aFrame->PresContext()->AppUnitsPerDevPixel(); |
2528 | | Color blueOrRed(aFrame->HasView() ? Color(0.f, 0.f, 1.f, 1.f) : |
2529 | | Color(1.f, 0.f, 0.f, 1.f)); |
2530 | | aDrawTarget->StrokeRect(NSRectToRect(r, appUnitsPerDevPixel), |
2531 | | ColorPattern(ToDeviceColor(blueOrRed))); |
2532 | | } |
2533 | | |
2534 | | static void PaintEventTargetBorder(nsIFrame* aFrame, DrawTarget* aDrawTarget, |
2535 | | const nsRect& aDirtyRect, nsPoint aPt) |
2536 | | { |
2537 | | nsRect r(aPt, aFrame->GetSize()); |
2538 | | int32_t appUnitsPerDevPixel = aFrame->PresContext()->AppUnitsPerDevPixel(); |
2539 | | ColorPattern purple(ToDeviceColor(Color(.5f, 0.f, .5f, 1.f))); |
2540 | | aDrawTarget->StrokeRect(NSRectToRect(r, appUnitsPerDevPixel), purple); |
2541 | | } |
2542 | | |
2543 | | static void |
2544 | | DisplayDebugBorders(nsDisplayListBuilder* aBuilder, nsIFrame* aFrame, |
2545 | | const nsDisplayListSet& aLists) { |
2546 | | // Draw a border around the child |
2547 | | // REVIEW: From nsContainerFrame::PaintChild |
2548 | | if (nsFrame::GetShowFrameBorders() && !aFrame->GetRect().IsEmpty()) { |
2549 | | aLists.Outlines()->AppendToTop( |
2550 | | MakeDisplayItem<nsDisplayGeneric>(aBuilder, aFrame, PaintDebugBorder, "DebugBorder", |
2551 | | DisplayItemType::TYPE_DEBUG_BORDER)); |
2552 | | } |
2553 | | // Draw a border around the current event target |
2554 | | if (nsFrame::GetShowEventTargetFrameBorder() && |
2555 | | aFrame->PresShell()->GetDrawEventTargetFrame() == aFrame) { |
2556 | | aLists.Outlines()->AppendToTop( |
2557 | | MakeDisplayItem<nsDisplayGeneric>(aBuilder, aFrame, PaintEventTargetBorder, "EventTargetBorder", |
2558 | | DisplayItemType::TYPE_EVENT_TARGET_BORDER)); |
2559 | | } |
2560 | | } |
2561 | | #endif |
2562 | | |
2563 | | static bool |
2564 | | IsScrollFrameActive(nsDisplayListBuilder* aBuilder, nsIScrollableFrame* aScrollableFrame) |
2565 | 0 | { |
2566 | 0 | return aScrollableFrame && aScrollableFrame->IsScrollingActive(aBuilder); |
2567 | 0 | } |
2568 | | |
2569 | | /** |
2570 | | * Returns whether a display item that gets created with the builder's current |
2571 | | * state will have a scrolled clip, i.e. a clip that is scrolled by a scroll |
2572 | | * frame which does not move the item itself. |
2573 | | */ |
2574 | | static bool |
2575 | | BuilderHasScrolledClip(nsDisplayListBuilder* aBuilder) |
2576 | 0 | { |
2577 | 0 | const DisplayItemClipChain* currentClip = |
2578 | 0 | aBuilder->ClipState().GetCurrentCombinedClipChain(aBuilder); |
2579 | 0 | if (!currentClip) { |
2580 | 0 | return false; |
2581 | 0 | } |
2582 | 0 | |
2583 | 0 | const ActiveScrolledRoot* currentClipASR = currentClip->mASR; |
2584 | 0 | const ActiveScrolledRoot* currentASR = aBuilder->CurrentActiveScrolledRoot(); |
2585 | 0 | return ActiveScrolledRoot::PickDescendant(currentClipASR, currentASR) != currentASR; |
2586 | 0 | } |
2587 | | |
2588 | | class AutoSaveRestoreContainsBlendMode |
2589 | | { |
2590 | | nsDisplayListBuilder& mBuilder; |
2591 | | bool mSavedContainsBlendMode; |
2592 | | public: |
2593 | | explicit AutoSaveRestoreContainsBlendMode(nsDisplayListBuilder& aBuilder) |
2594 | | : mBuilder(aBuilder) |
2595 | | , mSavedContainsBlendMode(aBuilder.ContainsBlendMode()) |
2596 | 0 | { } |
2597 | | |
2598 | 0 | ~AutoSaveRestoreContainsBlendMode() { |
2599 | 0 | mBuilder.SetContainsBlendMode(mSavedContainsBlendMode); |
2600 | 0 | } |
2601 | | }; |
2602 | | |
2603 | | static void |
2604 | | CheckForApzAwareEventHandlers(nsDisplayListBuilder* aBuilder, nsIFrame* aFrame) |
2605 | 0 | { |
2606 | 0 | if (aBuilder->GetAncestorHasApzAwareEventHandler()) { |
2607 | 0 | return; |
2608 | 0 | } |
2609 | 0 | |
2610 | 0 | nsIContent* content = aFrame->GetContent(); |
2611 | 0 | if (!content) { |
2612 | 0 | return; |
2613 | 0 | } |
2614 | 0 | |
2615 | 0 | if (content->IsNodeApzAware()) { |
2616 | 0 | aBuilder->SetAncestorHasApzAwareEventHandler(true); |
2617 | 0 | } |
2618 | 0 | } |
2619 | | |
2620 | | /** |
2621 | | * True if aDescendant participates the context aAncestor participating. |
2622 | | */ |
2623 | | static bool |
2624 | 0 | FrameParticipatesIn3DContext(nsIFrame* aAncestor, nsIFrame* aDescendant) { |
2625 | 0 | MOZ_ASSERT(aAncestor != aDescendant); |
2626 | 0 | MOZ_ASSERT(aAncestor->Extend3DContext()); |
2627 | 0 |
|
2628 | 0 | nsIFrame* ancestor = aAncestor->FirstContinuation(); |
2629 | 0 | MOZ_ASSERT(ancestor->IsPrimaryFrame()); |
2630 | 0 |
|
2631 | 0 | nsIFrame* frame; |
2632 | 0 | for (frame = aDescendant->GetClosestFlattenedTreeAncestorPrimaryFrame(); |
2633 | 0 | frame && ancestor != frame; |
2634 | 0 | frame = frame->GetClosestFlattenedTreeAncestorPrimaryFrame()) { |
2635 | 0 | if (!frame->Extend3DContext()) { |
2636 | 0 | return false; |
2637 | 0 | } |
2638 | 0 | } |
2639 | 0 |
|
2640 | 0 | MOZ_ASSERT(frame == ancestor); |
2641 | 0 | return true; |
2642 | 0 | } |
2643 | | |
2644 | | static bool |
2645 | | ItemParticipatesIn3DContext(nsIFrame* aAncestor, nsDisplayItem* aItem) |
2646 | 0 | { |
2647 | 0 | nsIFrame* transformFrame; |
2648 | 0 | if (aItem->GetType() == DisplayItemType::TYPE_TRANSFORM || |
2649 | 0 | aItem->GetType() == DisplayItemType::TYPE_PERSPECTIVE) { |
2650 | 0 | transformFrame = aItem->Frame(); |
2651 | 0 | } else { |
2652 | 0 | return false; |
2653 | 0 | } |
2654 | 0 | if (aAncestor == transformFrame) { |
2655 | 0 | return true; |
2656 | 0 | } |
2657 | 0 | return FrameParticipatesIn3DContext(aAncestor, transformFrame); |
2658 | 0 | } |
2659 | | |
2660 | | static void |
2661 | | WrapSeparatorTransform(nsDisplayListBuilder* aBuilder, nsIFrame* aFrame, |
2662 | | nsDisplayList* aSource, nsDisplayList* aTarget, |
2663 | 0 | int aIndex) { |
2664 | 0 | if (!aSource->IsEmpty()) { |
2665 | 0 | nsDisplayTransform *sepIdItem = |
2666 | 0 | MakeDisplayItem<nsDisplayTransform>(aBuilder, aFrame, aSource, |
2667 | 0 | aBuilder->GetVisibleRect(), Matrix4x4(), aIndex); |
2668 | 0 | sepIdItem->SetNoExtendContext(); |
2669 | 0 | aTarget->AppendToTop(sepIdItem); |
2670 | 0 | } |
2671 | 0 | } |
2672 | | |
2673 | | // Try to compute a clip rect to bound the contents of the mask item |
2674 | | // that will be built for |aMaskedFrame|. If we're not able to compute |
2675 | | // one, return an empty Maybe. |
2676 | | // The returned clip rect, if there is one, is relative to |aMaskedFrame|. |
2677 | | static Maybe<nsRect> |
2678 | | ComputeClipForMaskItem(nsDisplayListBuilder* aBuilder, nsIFrame* aMaskedFrame, |
2679 | | bool aHandleOpacity) |
2680 | 0 | { |
2681 | 0 | const nsStyleSVGReset* svgReset = aMaskedFrame->StyleSVGReset(); |
2682 | 0 |
|
2683 | 0 | nsSVGUtils::MaskUsage maskUsage; |
2684 | 0 | nsSVGUtils::DetermineMaskUsage(aMaskedFrame, aHandleOpacity, maskUsage); |
2685 | 0 |
|
2686 | 0 | nsPoint offsetToUserSpace = nsLayoutUtils::ComputeOffsetToUserSpace(aBuilder, aMaskedFrame); |
2687 | 0 | int32_t devPixelRatio = aMaskedFrame->PresContext()->AppUnitsPerDevPixel(); |
2688 | 0 | gfxPoint devPixelOffsetToUserSpace = nsLayoutUtils::PointToGfxPoint( |
2689 | 0 | offsetToUserSpace, devPixelRatio); |
2690 | 0 | gfxMatrix cssToDevMatrix = nsSVGUtils::GetCSSPxToDevPxMatrix(aMaskedFrame); |
2691 | 0 |
|
2692 | 0 | nsPoint toReferenceFrame; |
2693 | 0 | aBuilder->FindReferenceFrameFor(aMaskedFrame, &toReferenceFrame); |
2694 | 0 |
|
2695 | 0 | Maybe<gfxRect> combinedClip; |
2696 | 0 | if (maskUsage.shouldApplyBasicShapeOrPath) { |
2697 | 0 | Rect result = nsCSSClipPathInstance::GetBoundingRectForBasicShapeOrPathClip( |
2698 | 0 | aMaskedFrame, svgReset->mClipPath); |
2699 | 0 | combinedClip = Some(ThebesRect(result)); |
2700 | 0 | } else if (maskUsage.shouldApplyClipPath) { |
2701 | 0 | gfxRect result = nsSVGUtils::GetBBox(aMaskedFrame, |
2702 | 0 | nsSVGUtils::eBBoxIncludeClipped | |
2703 | 0 | nsSVGUtils::eBBoxIncludeFill | |
2704 | 0 | nsSVGUtils::eBBoxIncludeMarkers | |
2705 | 0 | nsSVGUtils::eBBoxIncludeStroke | |
2706 | 0 | nsSVGUtils::eDoNotClipToBBoxOfContentInsideClipPath); |
2707 | 0 | combinedClip = Some(cssToDevMatrix.TransformBounds(result)); |
2708 | 0 | } else { |
2709 | 0 | // The code for this case is adapted from ComputeMaskGeometry(). |
2710 | 0 |
|
2711 | 0 | nsRect borderArea(toReferenceFrame, aMaskedFrame->GetSize()); |
2712 | 0 | borderArea -= offsetToUserSpace; |
2713 | 0 |
|
2714 | 0 | // Use an infinite dirty rect to pass into nsCSSRendering:: |
2715 | 0 | // GetImageLayerClip() because we don't have an actual dirty rect to |
2716 | 0 | // pass in. This is fine because the only time GetImageLayerClip() will |
2717 | 0 | // not intersect the incoming dirty rect with something is in the "NoClip" |
2718 | 0 | // case, and we handle that specially. |
2719 | 0 | nsRect dirtyRect(nscoord_MIN/2, nscoord_MIN/2, nscoord_MAX, nscoord_MAX); |
2720 | 0 |
|
2721 | 0 | nsIFrame* firstFrame = nsLayoutUtils::FirstContinuationOrIBSplitSibling(aMaskedFrame); |
2722 | 0 | SVGObserverUtils::EffectProperties effectProperties = |
2723 | 0 | SVGObserverUtils::GetEffectProperties(firstFrame); |
2724 | 0 | nsTArray<nsSVGMaskFrame*> maskFrames = effectProperties.GetMaskFrames(); |
2725 | 0 |
|
2726 | 0 | for (uint32_t i = 0; i < maskFrames.Length(); ++i) { |
2727 | 0 | gfxRect clipArea; |
2728 | 0 | if (maskFrames[i]) { |
2729 | 0 | clipArea = maskFrames[i]->GetMaskArea(aMaskedFrame); |
2730 | 0 | clipArea = cssToDevMatrix.TransformBounds(clipArea); |
2731 | 0 | } else { |
2732 | 0 | const auto& layer = svgReset->mMask.mLayers[i]; |
2733 | 0 | if (layer.mClip == StyleGeometryBox::NoClip) { |
2734 | 0 | return Nothing(); |
2735 | 0 | } |
2736 | 0 | |
2737 | 0 | nsCSSRendering::ImageLayerClipState clipState; |
2738 | 0 | nsCSSRendering::GetImageLayerClip(layer, aMaskedFrame, |
2739 | 0 | *aMaskedFrame->StyleBorder(), |
2740 | 0 | borderArea, dirtyRect, |
2741 | 0 | false /* aWillPaintBorder */, |
2742 | 0 | devPixelRatio, &clipState); |
2743 | 0 | clipArea = clipState.mDirtyRectInDevPx; |
2744 | 0 | } |
2745 | 0 | combinedClip = UnionMaybeRects(combinedClip, Some(clipArea)); |
2746 | 0 | } |
2747 | 0 | } |
2748 | 0 | if (combinedClip) { |
2749 | 0 | if (combinedClip->IsEmpty()) { |
2750 | 0 | // *clipForMask might be empty if all mask references are not resolvable |
2751 | 0 | // or the size of them are empty. We still need to create a transparent mask |
2752 | 0 | // before bug 1276834 fixed, so don't clip ctx by an empty rectangle for for |
2753 | 0 | // now. |
2754 | 0 | return Nothing(); |
2755 | 0 | } |
2756 | 0 | |
2757 | 0 | // Convert to user space. |
2758 | 0 | *combinedClip += devPixelOffsetToUserSpace; |
2759 | 0 |
|
2760 | 0 | // Round the clip out. In FrameLayerBuilder we round clips to nearest |
2761 | 0 | // pixels, and if we have a really thin clip here, that can cause the |
2762 | 0 | // clip to become empty if we didn't round out here. |
2763 | 0 | // The rounding happens in coordinates that are relative to the reference |
2764 | 0 | // frame, which matches what FrameLayerBuilder does. |
2765 | 0 | combinedClip->RoundOut(); |
2766 | 0 |
|
2767 | 0 | // Convert to app units. |
2768 | 0 | nsRect result = nsLayoutUtils::RoundGfxRectToAppRect(*combinedClip, devPixelRatio); |
2769 | 0 |
|
2770 | 0 | // The resulting clip is relative to the reference frame, but the caller |
2771 | 0 | // expects it to be relative to the masked frame, so adjust it. |
2772 | 0 | result -= toReferenceFrame; |
2773 | 0 | return Some(result); |
2774 | 0 | } |
2775 | 0 | return Nothing(); |
2776 | 0 | } |
2777 | | |
2778 | | struct AutoCheckBuilder { |
2779 | | explicit AutoCheckBuilder(nsDisplayListBuilder* aBuilder) |
2780 | | : mBuilder(aBuilder) |
2781 | 0 | { |
2782 | 0 | aBuilder->Check(); |
2783 | 0 | } |
2784 | | |
2785 | | ~AutoCheckBuilder() |
2786 | 0 | { |
2787 | 0 | mBuilder->Check(); |
2788 | 0 | } |
2789 | | |
2790 | | nsDisplayListBuilder* mBuilder; |
2791 | | }; |
2792 | | |
2793 | | void |
2794 | | nsIFrame::BuildDisplayListForStackingContext(nsDisplayListBuilder* aBuilder, |
2795 | | nsDisplayList* aList, |
2796 | 0 | bool* aCreatedContainerItem) { |
2797 | 0 | AutoCheckBuilder check(aBuilder); |
2798 | 0 | if (GetStateBits() & NS_FRAME_TOO_DEEP_IN_FRAME_TREE) |
2799 | 0 | return; |
2800 | 0 | |
2801 | 0 | // Replaced elements have their visibility handled here, because |
2802 | 0 | // they're visually atomic |
2803 | 0 | if (IsFrameOfType(eReplaced) && !IsVisibleForPainting(aBuilder)) |
2804 | 0 | return; |
2805 | 0 | |
2806 | 0 | const nsStyleDisplay* disp = StyleDisplay(); |
2807 | 0 | const nsStyleEffects* effects = StyleEffects(); |
2808 | 0 | EffectSet* effectSet = EffectSet::GetEffectSet(this); |
2809 | 0 | // We can stop right away if this is a zero-opacity stacking context and |
2810 | 0 | // we're painting, and we're not animating opacity. Don't do this |
2811 | 0 | // if we're going to compute plugin geometry, since opacity-0 plugins |
2812 | 0 | // need to have display items built for them. |
2813 | 0 | bool opacityItemForEventsAndPluginsOnly = false; |
2814 | 0 | if (effects->mOpacity == 0.0 && aBuilder->IsForPainting() && |
2815 | 0 | !(disp->mWillChangeBitField & NS_STYLE_WILL_CHANGE_OPACITY) && |
2816 | 0 | !nsLayoutUtils::HasAnimationOfProperty(effectSet, eCSSProperty_opacity)) { |
2817 | 0 | if (aBuilder->WillComputePluginGeometry()) { |
2818 | 0 | opacityItemForEventsAndPluginsOnly = true; |
2819 | 0 | } else { |
2820 | 0 | return; |
2821 | 0 | } |
2822 | 0 | } |
2823 | 0 | |
2824 | 0 | if (disp->mWillChangeBitField != 0) { |
2825 | 0 | aBuilder->AddToWillChangeBudget(this, GetSize()); |
2826 | 0 | } |
2827 | 0 |
|
2828 | 0 | // For preserves3d, use the dirty rect already installed on the |
2829 | 0 | // builder, since aDirtyRect maybe distorted for transforms along |
2830 | 0 | // the chain. |
2831 | 0 | nsRect visibleRect = aBuilder->GetVisibleRect(); |
2832 | 0 | nsRect dirtyRect = aBuilder->GetDirtyRect(); |
2833 | 0 |
|
2834 | 0 | const bool isTransformed = IsTransformed(disp); |
2835 | 0 | const bool hasPerspective = isTransformed && HasPerspective(disp); |
2836 | 0 | const bool extend3DContext = Extend3DContext(disp, effectSet); |
2837 | 0 | const bool combines3DTransformWithAncestors = |
2838 | 0 | (extend3DContext || isTransformed) && Combines3DTransformWithAncestors(disp); |
2839 | 0 |
|
2840 | 0 | Maybe<nsDisplayListBuilder::AutoPreserves3DContext> autoPreserves3DContext; |
2841 | 0 | if (extend3DContext && !combines3DTransformWithAncestors) { |
2842 | 0 | // Start a new preserves3d context to keep informations on |
2843 | 0 | // nsDisplayListBuilder. |
2844 | 0 | autoPreserves3DContext.emplace(aBuilder); |
2845 | 0 | // Save dirty rect on the builder to avoid being distorted for |
2846 | 0 | // multiple transforms along the chain. |
2847 | 0 | aBuilder->SavePreserves3DRect(); |
2848 | 0 |
|
2849 | 0 | // We rebuild everything within preserve-3d and don't try |
2850 | 0 | // to retain, so override the dirty rect now. |
2851 | 0 | if (aBuilder->IsRetainingDisplayList()) { |
2852 | 0 | dirtyRect = visibleRect; |
2853 | 0 | aBuilder->SetDisablePartialUpdates(true); |
2854 | 0 | } |
2855 | 0 | } |
2856 | 0 |
|
2857 | 0 | // reset blend mode so we can keep track if this stacking context needs have |
2858 | 0 | // a nsDisplayBlendContainer. Set the blend mode back when the routine exits |
2859 | 0 | // so we keep track if the parent stacking context needs a container too. |
2860 | 0 | AutoSaveRestoreContainsBlendMode autoRestoreBlendMode(*aBuilder); |
2861 | 0 | aBuilder->SetContainsBlendMode(false); |
2862 | 0 |
|
2863 | 0 | nsRect visibleRectOutsideTransform = visibleRect; |
2864 | 0 | bool allowAsyncAnimation = false; |
2865 | 0 | bool inTransform = aBuilder->IsInTransform(); |
2866 | 0 | if (isTransformed) { |
2867 | 0 | const nsRect overflow = GetVisualOverflowRectRelativeToSelf(); |
2868 | 0 | nsDisplayTransform::PrerenderDecision decision = |
2869 | 0 | nsDisplayTransform::ShouldPrerenderTransformedContent(aBuilder, this, &dirtyRect); |
2870 | 0 | switch (decision) { |
2871 | 0 | case nsDisplayTransform::FullPrerender: |
2872 | 0 | allowAsyncAnimation = true; |
2873 | 0 | visibleRect = dirtyRect; |
2874 | 0 | break; |
2875 | 0 | case nsDisplayTransform::PartialPrerender: |
2876 | 0 | allowAsyncAnimation = true; |
2877 | 0 | visibleRect = dirtyRect; |
2878 | 0 | MOZ_FALLTHROUGH; |
2879 | 0 | // fall through to the NoPrerender case |
2880 | 0 | case nsDisplayTransform::NoPrerender: |
2881 | 0 | if (overflow.IsEmpty() && !extend3DContext) { |
2882 | 0 | return; |
2883 | 0 | } |
2884 | 0 | |
2885 | 0 | // If we're in preserve-3d then grab the dirty rect that was given to the root |
2886 | 0 | // and transform using the combined transform. |
2887 | 0 | if (combines3DTransformWithAncestors) { |
2888 | 0 | visibleRect = dirtyRect = aBuilder->GetPreserves3DRect(); |
2889 | 0 | } |
2890 | 0 |
|
2891 | 0 | nsRect untransformedDirtyRect; |
2892 | 0 | if (nsDisplayTransform::UntransformRect(dirtyRect, overflow, this, |
2893 | 0 | &untransformedDirtyRect)) { |
2894 | 0 | dirtyRect = untransformedDirtyRect; |
2895 | 0 | nsDisplayTransform::UntransformRect(visibleRect, overflow, this, &visibleRect); |
2896 | 0 | } else { |
2897 | 0 | // This should only happen if the transform is singular, in which case nothing is visible anyway |
2898 | 0 | dirtyRect.SetEmpty(); |
2899 | 0 | visibleRect.SetEmpty(); |
2900 | 0 | } |
2901 | 0 | } |
2902 | 0 | inTransform = true; |
2903 | 0 | } else if (IsFixedPosContainingBlock()) { |
2904 | 0 | // Restict the building area to the overflow rect for these frames, since |
2905 | 0 | // RetainedDisplayListBuilder uses it to know if the size of the stacking |
2906 | 0 | // context changed. |
2907 | 0 | visibleRect.IntersectRect(visibleRect, GetVisualOverflowRect()); |
2908 | 0 | dirtyRect.IntersectRect(dirtyRect, GetVisualOverflowRect()); |
2909 | 0 | } |
2910 | 0 |
|
2911 | 0 | bool hasOverrideDirtyRect = false; |
2912 | 0 | // If we have an override dirty region, and neither us nor our ancestors are |
2913 | 0 | // modified, then use it. |
2914 | 0 | if (HasOverrideDirtyRegion() && !aBuilder->InInvalidSubtree() && !IsFrameModified()) { |
2915 | 0 | nsDisplayListBuilder::DisplayListBuildingData* data = |
2916 | 0 | GetProperty(nsDisplayListBuilder::DisplayListBuildingRect()); |
2917 | 0 | if (data) { |
2918 | 0 | dirtyRect = data->mDirtyRect.Intersect(visibleRect); |
2919 | 0 | hasOverrideDirtyRect = true; |
2920 | 0 | } |
2921 | 0 | } |
2922 | 0 |
|
2923 | 0 | bool usingFilter = StyleEffects()->HasFilters(); |
2924 | 0 | bool usingMask = nsSVGIntegrationUtils::UsingMaskOrClipPathForFrame(this); |
2925 | 0 | bool usingSVGEffects = usingFilter || usingMask; |
2926 | 0 |
|
2927 | 0 | nsRect visibleRectOutsideSVGEffects = visibleRect; |
2928 | 0 | nsDisplayList hoistedScrollInfoItemsStorage; |
2929 | 0 | if (usingSVGEffects) { |
2930 | 0 | dirtyRect = |
2931 | 0 | nsSVGIntegrationUtils::GetRequiredSourceForInvalidArea(this, dirtyRect); |
2932 | 0 | visibleRect = |
2933 | 0 | nsSVGIntegrationUtils::GetRequiredSourceForInvalidArea(this, visibleRect); |
2934 | 0 | aBuilder->EnterSVGEffectsContents(&hoistedScrollInfoItemsStorage); |
2935 | 0 | } |
2936 | 0 |
|
2937 | 0 |
|
2938 | 0 | bool needsActiveOpacityLayer = false; |
2939 | 0 | // We build an opacity item if it's not going to be drawn by SVG content, or |
2940 | 0 | // SVG effects. SVG effects won't handle the opacity if we want an active |
2941 | 0 | // layer (for async animations), see |
2942 | 0 | // nsSVGIntegrationsUtils::PaintMaskAndClipPath or |
2943 | 0 | // nsSVGIntegrationsUtils::PaintFilter. |
2944 | 0 | bool useOpacity = HasVisualOpacity(effectSet) && |
2945 | 0 | !nsSVGUtils::CanOptimizeOpacity(this) && |
2946 | 0 | ((needsActiveOpacityLayer = nsDisplayOpacity::NeedsActiveLayer(aBuilder, this)) || !usingSVGEffects); |
2947 | 0 | bool useBlendMode = effects->mMixBlendMode != NS_STYLE_BLEND_NORMAL; |
2948 | 0 | bool useStickyPosition = disp->mPosition == NS_STYLE_POSITION_STICKY && |
2949 | 0 | IsScrollFrameActive(aBuilder, |
2950 | 0 | nsLayoutUtils::GetNearestScrollableFrame(GetParent(), |
2951 | 0 | nsLayoutUtils::SCROLLABLE_SAME_DOC | |
2952 | 0 | nsLayoutUtils::SCROLLABLE_INCLUDE_HIDDEN)); |
2953 | 0 | bool useFixedPosition = disp->mPosition == NS_STYLE_POSITION_FIXED && |
2954 | 0 | (nsLayoutUtils::IsFixedPosFrameInDisplayPort(this) || BuilderHasScrolledClip(aBuilder)); |
2955 | 0 |
|
2956 | 0 | nsDisplayListBuilder::AutoBuildingDisplayList |
2957 | 0 | buildingDisplayList(aBuilder, this, visibleRect, dirtyRect, true); |
2958 | 0 |
|
2959 | 0 | // Depending on the effects that are applied to this frame, we can create |
2960 | 0 | // multiple container display items and wrap them around our contents. |
2961 | 0 | // This enum lists all the potential container display items, in the order |
2962 | 0 | // outside to inside. |
2963 | 0 | enum class ContainerItemType : uint8_t { |
2964 | 0 | eNone = 0, |
2965 | 0 | eOwnLayerIfNeeded, |
2966 | 0 | eBlendMode, |
2967 | 0 | eFixedPosition, |
2968 | 0 | eOwnLayerForTransformWithRoundedClip, |
2969 | 0 | ePerspective, |
2970 | 0 | eTransform, |
2971 | 0 | eSeparatorTransforms, |
2972 | 0 | eOpacity, |
2973 | 0 | eFilter, |
2974 | 0 | eBlendContainer |
2975 | 0 | }; |
2976 | 0 |
|
2977 | 0 | nsDisplayListBuilder::AutoContainerASRTracker contASRTracker(aBuilder); |
2978 | 0 |
|
2979 | 0 | DisplayListClipState::AutoSaveRestore clipState(aBuilder); |
2980 | 0 |
|
2981 | 0 | // If there is a current clip, then depending on the container items we |
2982 | 0 | // create, different things can happen to it. Some container items simply |
2983 | 0 | // propagate the clip to their children and aren't clipped themselves. |
2984 | 0 | // But other container items, especially those that establish a different |
2985 | 0 | // geometry for their contents (e.g. transforms), capture the clip on |
2986 | 0 | // themselves and unset the clip for their contents. If we create more than |
2987 | 0 | // one of those container items, the clip will be captured on the outermost |
2988 | 0 | // one and the inner container items will be unclipped. |
2989 | 0 | ContainerItemType clipCapturedBy = ContainerItemType::eNone; |
2990 | 0 | if (useFixedPosition) { |
2991 | 0 | clipCapturedBy = ContainerItemType::eFixedPosition; |
2992 | 0 | } else if (isTransformed) { |
2993 | 0 | const DisplayItemClipChain* currentClip = |
2994 | 0 | aBuilder->ClipState().GetCurrentCombinedClipChain(aBuilder); |
2995 | 0 | if ((hasPerspective || extend3DContext) && |
2996 | 0 | (currentClip && currentClip->HasRoundedCorners())) { |
2997 | 0 | // If we're creating an nsDisplayTransform item that is going to combine |
2998 | 0 | // its transform with its children (preserve-3d or perspective), then we |
2999 | 0 | // can't have an intermediate surface. Mask layers force an intermediate |
3000 | 0 | // surface, so if we're going to need both then create a separate |
3001 | 0 | // wrapping layer for the mask. |
3002 | 0 | clipCapturedBy = ContainerItemType::eOwnLayerForTransformWithRoundedClip; |
3003 | 0 | } else if (hasPerspective) { |
3004 | 0 | clipCapturedBy = ContainerItemType::ePerspective; |
3005 | 0 | } else { |
3006 | 0 | clipCapturedBy = ContainerItemType::eTransform; |
3007 | 0 | } |
3008 | 0 | } else if (usingFilter) { |
3009 | 0 | clipCapturedBy = ContainerItemType::eFilter; |
3010 | 0 | } |
3011 | 0 |
|
3012 | 0 | if (clipCapturedBy != ContainerItemType::eNone) { |
3013 | 0 | clipState.Clear(); |
3014 | 0 | } |
3015 | 0 |
|
3016 | 0 | Maybe<nsRect> clipForMask; |
3017 | 0 | if (usingMask) { |
3018 | 0 | clipForMask = ComputeClipForMaskItem(aBuilder, this, !useOpacity); |
3019 | 0 | } |
3020 | 0 |
|
3021 | 0 | nsDisplayListCollection set(aBuilder); |
3022 | 0 | { |
3023 | 0 | DisplayListClipState::AutoSaveRestore nestedClipState(aBuilder); |
3024 | 0 | nsDisplayListBuilder::AutoInTransformSetter |
3025 | 0 | inTransformSetter(aBuilder, inTransform); |
3026 | 0 | nsDisplayListBuilder::AutoEnterFilter |
3027 | 0 | filterASRSetter(aBuilder, usingFilter); |
3028 | 0 |
|
3029 | 0 | CheckForApzAwareEventHandlers(aBuilder, this); |
3030 | 0 |
|
3031 | 0 | Maybe<nsRect> contentClip = |
3032 | 0 | GetClipPropClipRect(disp, effects, GetSize()); |
3033 | 0 |
|
3034 | 0 | if (usingMask) { |
3035 | 0 | contentClip = IntersectMaybeRects(contentClip, clipForMask); |
3036 | 0 | } |
3037 | 0 |
|
3038 | 0 | if (contentClip) { |
3039 | 0 | aBuilder->IntersectDirtyRect(*contentClip); |
3040 | 0 | aBuilder->IntersectVisibleRect(*contentClip); |
3041 | 0 | nestedClipState.ClipContentDescendants(*contentClip + |
3042 | 0 | aBuilder->ToReferenceFrame(this)); |
3043 | 0 | } |
3044 | 0 |
|
3045 | 0 | // extend3DContext also guarantees that applyAbsPosClipping and usingSVGEffects are false |
3046 | 0 | // We only modify the preserve-3d rect if we are the top of a preserve-3d heirarchy |
3047 | 0 | if (extend3DContext) { |
3048 | 0 | // Mark these first so MarkAbsoluteFramesForDisplayList knows if we are |
3049 | 0 | // going to be forced to descend into frames. |
3050 | 0 | aBuilder->MarkPreserve3DFramesForDisplayList(this); |
3051 | 0 | } |
3052 | 0 |
|
3053 | 0 | aBuilder->AdjustWindowDraggingRegion(this); |
3054 | 0 |
|
3055 | 0 | aBuilder->BuildCompositorHitTestInfoIfNeeded(this, set.BorderBackground(), |
3056 | 0 | true); |
3057 | 0 |
|
3058 | 0 | MarkAbsoluteFramesForDisplayList(aBuilder); |
3059 | 0 | aBuilder->Check(); |
3060 | 0 | BuildDisplayList(aBuilder, set); |
3061 | 0 | aBuilder->Check(); |
3062 | 0 |
|
3063 | 0 | // Blend modes are a real pain for retained display lists. We build a blend |
3064 | 0 | // container item if the built list contains any blend mode items within |
3065 | 0 | // the current stacking context. This can change without an invalidation |
3066 | 0 | // to the stacking context frame, or the blend mode frame (e.g. by moving |
3067 | 0 | // an intermediate frame). |
3068 | 0 | // When we gain/remove a blend container item, we need to mark this frame |
3069 | 0 | // as invalid and have the full display list for merging to track |
3070 | 0 | // the change correctly. |
3071 | 0 | // It seems really hard to track this in advance, as the bookkeeping |
3072 | 0 | // required to note which stacking contexts have blend descendants |
3073 | 0 | // is complex and likely to be buggy. |
3074 | 0 | // Instead we're doing the sad thing, detecting it afterwards, and just |
3075 | 0 | // repeating display list building if it changed. |
3076 | 0 | // We have to repeat building for the entire display list (or at least |
3077 | 0 | // the outer stacking context), since we need to mark this frame as invalid |
3078 | 0 | // to remove any existing content that isn't wrapped in the blend container, |
3079 | 0 | // and then we need to build content infront/behind the blend container |
3080 | 0 | // to get correct positioning during merging. |
3081 | 0 | if (aBuilder->ContainsBlendMode() && |
3082 | 0 | aBuilder->IsRetainingDisplayList()) { |
3083 | 0 | if (!aBuilder->GetDirtyRect().Contains(aBuilder->GetVisibleRect())) { |
3084 | 0 | aBuilder->SetPartialBuildFailed(true); |
3085 | 0 | } else { |
3086 | 0 | aBuilder->SetDisablePartialUpdates(true); |
3087 | 0 | } |
3088 | 0 | } |
3089 | 0 | } |
3090 | 0 |
|
3091 | 0 | if (aBuilder->IsBackgroundOnly()) { |
3092 | 0 | set.BlockBorderBackgrounds()->DeleteAll(aBuilder); |
3093 | 0 | set.Floats()->DeleteAll(aBuilder); |
3094 | 0 | set.Content()->DeleteAll(aBuilder); |
3095 | 0 | set.PositionedDescendants()->DeleteAll(aBuilder); |
3096 | 0 | set.Outlines()->DeleteAll(aBuilder); |
3097 | 0 | } |
3098 | 0 |
|
3099 | 0 | if (hasOverrideDirtyRect && gfxPrefs::LayoutDisplayListShowArea()) { |
3100 | 0 | nsDisplaySolidColor* color = |
3101 | 0 | MakeDisplayItem<nsDisplaySolidColor>(aBuilder, this, |
3102 | 0 | dirtyRect + aBuilder->GetCurrentFrameOffsetToReferenceFrame(), |
3103 | 0 | NS_RGBA(255, 0, 0, 64), false); |
3104 | 0 | color->SetOverrideZIndex(INT32_MAX); |
3105 | 0 | set.PositionedDescendants()->AppendToTop(color); |
3106 | 0 | } |
3107 | 0 |
|
3108 | 0 | // Sort PositionedDescendants() in CSS 'z-order' order. The list is already |
3109 | 0 | // in content document order and SortByZOrder is a stable sort which |
3110 | 0 | // guarantees that boxes produced by the same element are placed together |
3111 | 0 | // in the sort. Consider a position:relative inline element that breaks |
3112 | 0 | // across lines and has absolutely positioned children; all the abs-pos |
3113 | 0 | // children should be z-ordered after all the boxes for the position:relative |
3114 | 0 | // element itself. |
3115 | 0 | set.PositionedDescendants()->SortByZOrder(); |
3116 | 0 |
|
3117 | 0 | nsDisplayList resultList; |
3118 | 0 | // Now follow the rules of http://www.w3.org/TR/CSS21/zindex.html |
3119 | 0 | // 1,2: backgrounds and borders |
3120 | 0 | resultList.AppendToTop(set.BorderBackground()); |
3121 | 0 | // 3: negative z-index children. |
3122 | 0 | for (;;) { |
3123 | 0 | nsDisplayItem* item = set.PositionedDescendants()->GetBottom(); |
3124 | 0 | if (item && item->ZIndex() < 0) { |
3125 | 0 | set.PositionedDescendants()->RemoveBottom(); |
3126 | 0 | resultList.AppendToTop(item); |
3127 | 0 | continue; |
3128 | 0 | } |
3129 | 0 | break; |
3130 | 0 | } |
3131 | 0 | // 4: block backgrounds |
3132 | 0 | resultList.AppendToTop(set.BlockBorderBackgrounds()); |
3133 | 0 | // 5: floats |
3134 | 0 | resultList.AppendToTop(set.Floats()); |
3135 | 0 | // 7: general content |
3136 | 0 | resultList.AppendToTop(set.Content()); |
3137 | 0 | // 7.5: outlines, in content tree order. We need to sort by content order |
3138 | 0 | // because an element with outline that breaks and has children with outline |
3139 | 0 | // might have placed child outline items between its own outline items. |
3140 | 0 | // The element's outline items need to all come before any child outline |
3141 | 0 | // items. |
3142 | 0 | nsIContent* content = GetContent(); |
3143 | 0 | if (!content) { |
3144 | 0 | content = PresContext()->Document()->GetRootElement(); |
3145 | 0 | } |
3146 | 0 | if (content) { |
3147 | 0 | set.Outlines()->SortByContentOrder(content); |
3148 | 0 | } |
3149 | | #ifdef DEBUG |
3150 | | DisplayDebugBorders(aBuilder, this, set); |
3151 | | #endif |
3152 | | resultList.AppendToTop(set.Outlines()); |
3153 | 0 | // 8, 9: non-negative z-index children |
3154 | 0 | resultList.AppendToTop(set.PositionedDescendants()); |
3155 | 0 |
|
3156 | 0 | // Get the ASR to use for the container items that we create here. |
3157 | 0 | const ActiveScrolledRoot* containerItemASR = contASRTracker.GetContainerASR(); |
3158 | 0 |
|
3159 | 0 | if (aCreatedContainerItem) { |
3160 | 0 | *aCreatedContainerItem = false; |
3161 | 0 | } |
3162 | 0 |
|
3163 | 0 | /* If adding both a nsDisplayBlendContainer and a nsDisplayBlendMode to the |
3164 | 0 | * same list, the nsDisplayBlendContainer should be added first. This only |
3165 | 0 | * happens when the element creating this stacking context has mix-blend-mode |
3166 | 0 | * and also contains a child which has mix-blend-mode. |
3167 | 0 | * The nsDisplayBlendContainer must be added to the list first, so it does not |
3168 | 0 | * isolate the containing element blending as well. |
3169 | 0 | */ |
3170 | 0 | if (aBuilder->ContainsBlendMode()) { |
3171 | 0 | DisplayListClipState::AutoSaveRestore blendContainerClipState(aBuilder); |
3172 | 0 | resultList.AppendToTop( |
3173 | 0 | nsDisplayBlendContainer::CreateForMixBlendMode(aBuilder, this, &resultList, |
3174 | 0 | containerItemASR)); |
3175 | 0 | if (aCreatedContainerItem) { |
3176 | 0 | *aCreatedContainerItem = true; |
3177 | 0 | } |
3178 | 0 | } |
3179 | 0 |
|
3180 | 0 | /* If there are any SVG effects, wrap the list up in an SVG effects item |
3181 | 0 | * (which also handles CSS group opacity). Note that we create an SVG effects |
3182 | 0 | * item even if resultList is empty, since a filter can produce graphical |
3183 | 0 | * output even if the element being filtered wouldn't otherwise do so. |
3184 | 0 | */ |
3185 | 0 | if (usingSVGEffects) { |
3186 | 0 | MOZ_ASSERT(usingFilter ||usingMask, |
3187 | 0 | "Beside filter & mask/clip-path, what else effect do we have?"); |
3188 | 0 |
|
3189 | 0 | if (clipCapturedBy == ContainerItemType::eFilter) { |
3190 | 0 | clipState.Restore(); |
3191 | 0 | } |
3192 | 0 | // Revert to the post-filter dirty rect. |
3193 | 0 | aBuilder->SetVisibleRect(visibleRectOutsideSVGEffects); |
3194 | 0 |
|
3195 | 0 | // Skip all filter effects while generating glyph mask. |
3196 | 0 | if (usingFilter && !aBuilder->IsForGenerateGlyphMask()) { |
3197 | 0 | // If we are going to create a mask display item, handle opacity effect |
3198 | 0 | // in that mask display item; Otherwise, take care of opacity in this |
3199 | 0 | // filter display item. |
3200 | 0 | bool handleOpacity = !usingMask && !useOpacity; |
3201 | 0 |
|
3202 | 0 | /* List now emptied, so add the new list to the top. */ |
3203 | 0 | resultList.AppendToTop( |
3204 | 0 | MakeDisplayItem<nsDisplayFilter>(aBuilder, this, &resultList, |
3205 | 0 | handleOpacity)); |
3206 | 0 | } |
3207 | 0 |
|
3208 | 0 | if (usingMask) { |
3209 | 0 | DisplayListClipState::AutoSaveRestore maskClipState(aBuilder); |
3210 | 0 | // The mask should move with aBuilder->CurrentActiveScrolledRoot(), so |
3211 | 0 | // that's the ASR we prefer to use for the mask item. However, we can |
3212 | 0 | // only do this if the mask if clipped with respect to that ASR, because |
3213 | 0 | // an item always needs to have finite bounds with respect to its ASR. |
3214 | 0 | // If we weren't able to compute a clip for the mask, we fall back to |
3215 | 0 | // using containerItemASR, which is the lowest common ancestor clip of |
3216 | 0 | // the mask's contents. That's not entirely crrect, but it satisfies |
3217 | 0 | // the base requirement of the ASR system (that items have finite bounds |
3218 | 0 | // wrt. their ASR). |
3219 | 0 | const ActiveScrolledRoot* maskASR = clipForMask.isSome() |
3220 | 0 | ? aBuilder->CurrentActiveScrolledRoot() |
3221 | 0 | : containerItemASR; |
3222 | 0 | /* List now emptied, so add the new list to the top. */ |
3223 | 0 | resultList.AppendToTop( |
3224 | 0 | MakeDisplayItem<nsDisplayMask>(aBuilder, this, &resultList, !useOpacity, |
3225 | 0 | maskASR)); |
3226 | 0 | } |
3227 | 0 |
|
3228 | 0 | // Also add the hoisted scroll info items. We need those for APZ scrolling |
3229 | 0 | // because nsDisplayMask items can't build active layers. |
3230 | 0 | aBuilder->ExitSVGEffectsContents(); |
3231 | 0 | resultList.AppendToTop(&hoistedScrollInfoItemsStorage); |
3232 | 0 | if (aCreatedContainerItem) { |
3233 | 0 | *aCreatedContainerItem = false; |
3234 | 0 | } |
3235 | 0 | } |
3236 | 0 |
|
3237 | 0 | /* If the list is non-empty and there is CSS group opacity without SVG |
3238 | 0 | * effects, wrap it up in an opacity item. |
3239 | 0 | */ |
3240 | 0 | if (useOpacity) { |
3241 | 0 | // Don't clip nsDisplayOpacity items. We clip their descendants instead. |
3242 | 0 | // The clip we would set on an element with opacity would clip |
3243 | 0 | // all descendant content, but some should not be clipped. |
3244 | 0 | DisplayListClipState::AutoSaveRestore opacityClipState(aBuilder); |
3245 | 0 | resultList.AppendToTop( |
3246 | 0 | MakeDisplayItem<nsDisplayOpacity>(aBuilder, this, &resultList, |
3247 | 0 | containerItemASR, |
3248 | 0 | opacityItemForEventsAndPluginsOnly, |
3249 | 0 | needsActiveOpacityLayer)); |
3250 | 0 | if (aCreatedContainerItem) { |
3251 | 0 | *aCreatedContainerItem = true; |
3252 | 0 | } |
3253 | 0 | } |
3254 | 0 |
|
3255 | 0 | /* If we're going to apply a transformation and don't have preserve-3d set, wrap |
3256 | 0 | * everything in an nsDisplayTransform. If there's nothing in the list, don't add |
3257 | 0 | * anything. |
3258 | 0 | * |
3259 | 0 | * For the preserve-3d case we want to individually wrap every child in the list with |
3260 | 0 | * a separate nsDisplayTransform instead. When the child is already an nsDisplayTransform, |
3261 | 0 | * we can skip this step, as the computed transform will already include our own. |
3262 | 0 | * |
3263 | 0 | * We also traverse into sublists created by nsDisplayWrapList, so that we find all the |
3264 | 0 | * correct children. |
3265 | 0 | */ |
3266 | 0 | if (isTransformed && extend3DContext) { |
3267 | 0 | // Install dummy nsDisplayTransform as a leaf containing |
3268 | 0 | // descendants not participating this 3D rendering context. |
3269 | 0 | nsDisplayList nonparticipants; |
3270 | 0 | nsDisplayList participants; |
3271 | 0 | int index = 1; |
3272 | 0 |
|
3273 | 0 | while (nsDisplayItem* item = resultList.RemoveBottom()) { |
3274 | 0 | if (ItemParticipatesIn3DContext(this, item) && !item->GetClip().HasClip()) { |
3275 | 0 | // The frame of this item participates the same 3D context. |
3276 | 0 | WrapSeparatorTransform(aBuilder, this, &nonparticipants, &participants, index++); |
3277 | 0 | participants.AppendToTop(item); |
3278 | 0 | } else { |
3279 | 0 | // The frame of the item doesn't participate the current |
3280 | 0 | // context, or has no transform. |
3281 | 0 | // |
3282 | 0 | // For items participating but not transformed, they are add |
3283 | 0 | // to nonparticipants to get a separator layer for handling |
3284 | 0 | // clips, if there is, on an intermediate surface. |
3285 | 0 | // \see ContainerLayer::DefaultComputeEffectiveTransforms(). |
3286 | 0 | nonparticipants.AppendToTop(item); |
3287 | 0 | } |
3288 | 0 | } |
3289 | 0 | WrapSeparatorTransform(aBuilder, this, &nonparticipants, &participants, index++); |
3290 | 0 | resultList.AppendToTop(&participants); |
3291 | 0 | } |
3292 | 0 |
|
3293 | 0 | if (isTransformed) { |
3294 | 0 | if (clipCapturedBy == ContainerItemType::eTransform) { |
3295 | 0 | // Restore clip state now so nsDisplayTransform is clipped properly. |
3296 | 0 | clipState.Restore(); |
3297 | 0 | } |
3298 | 0 | // Revert to the dirtyrect coming in from the parent, without our transform |
3299 | 0 | // taken into account. |
3300 | 0 | aBuilder->SetVisibleRect(visibleRectOutsideTransform); |
3301 | 0 | // Revert to the outer reference frame and offset because all display |
3302 | 0 | // items we create from now on are outside the transform. |
3303 | 0 | nsPoint toOuterReferenceFrame; |
3304 | 0 | const nsIFrame* outerReferenceFrame = this; |
3305 | 0 | if (this != aBuilder->RootReferenceFrame()) { |
3306 | 0 | outerReferenceFrame = |
3307 | 0 | aBuilder->FindReferenceFrameFor(GetParent(), &toOuterReferenceFrame); |
3308 | 0 | } |
3309 | 0 | buildingDisplayList.SetReferenceFrameAndCurrentOffset(outerReferenceFrame, |
3310 | 0 | GetOffsetToCrossDoc(outerReferenceFrame)); |
3311 | 0 |
|
3312 | 0 | nsDisplayTransform *transformItem = |
3313 | 0 | MakeDisplayItem<nsDisplayTransform>(aBuilder, this, |
3314 | 0 | &resultList, visibleRect, 0, |
3315 | 0 | allowAsyncAnimation); |
3316 | 0 | resultList.AppendToTop(transformItem); |
3317 | 0 |
|
3318 | 0 | if (hasPerspective) { |
3319 | 0 | if (clipCapturedBy == ContainerItemType::ePerspective) { |
3320 | 0 | clipState.Restore(); |
3321 | 0 | } |
3322 | 0 | resultList.AppendToTop( |
3323 | 0 | MakeDisplayItem<nsDisplayPerspective>( |
3324 | 0 | aBuilder, this, &resultList)); |
3325 | 0 | } |
3326 | 0 |
|
3327 | 0 | if (aCreatedContainerItem) { |
3328 | 0 | *aCreatedContainerItem = true; |
3329 | 0 | } |
3330 | 0 | } |
3331 | 0 |
|
3332 | 0 | if (clipCapturedBy == ContainerItemType::eOwnLayerForTransformWithRoundedClip) { |
3333 | 0 | clipState.Restore(); |
3334 | 0 | resultList.AppendToTop( |
3335 | 0 | MakeDisplayItem<nsDisplayOwnLayer>(aBuilder, this, &resultList, |
3336 | 0 | aBuilder->CurrentActiveScrolledRoot(), |
3337 | 0 | nsDisplayOwnLayerFlags::eNone, |
3338 | 0 | ScrollbarData{}, /* aForceActive = */ false)); |
3339 | 0 | if (aCreatedContainerItem) { |
3340 | 0 | *aCreatedContainerItem = true; |
3341 | 0 | } |
3342 | 0 | } |
3343 | 0 |
|
3344 | 0 | /* If we have sticky positioning, wrap it in a sticky position item. |
3345 | 0 | */ |
3346 | 0 | if (useFixedPosition) { |
3347 | 0 | if (clipCapturedBy == ContainerItemType::eFixedPosition) { |
3348 | 0 | clipState.Restore(); |
3349 | 0 | } |
3350 | 0 | // The ASR for the fixed item should be the ASR of our containing block, |
3351 | 0 | // which has been set as the builder's current ASR, unless this frame is |
3352 | 0 | // invisible and we hadn't saved display item data for it. In that case, |
3353 | 0 | // we need to take the containerItemASR since we might have fixed children. |
3354 | 0 | // For WebRender, we want to the know what |containerItemASR| is for the |
3355 | 0 | // case where the fixed-pos item is not a "real" fixed-pos item (e.g. it's |
3356 | 0 | // nested inside a scrolling transform), so we stash that on the display |
3357 | 0 | // item as well. |
3358 | 0 | const ActiveScrolledRoot* fixedASR = |
3359 | 0 | ActiveScrolledRoot::PickAncestor(containerItemASR, aBuilder->CurrentActiveScrolledRoot()); |
3360 | 0 | resultList.AppendToTop( |
3361 | 0 | MakeDisplayItem<nsDisplayFixedPosition>(aBuilder, this, &resultList, |
3362 | 0 | fixedASR, containerItemASR)); |
3363 | 0 | if (aCreatedContainerItem) { |
3364 | 0 | *aCreatedContainerItem = true; |
3365 | 0 | } |
3366 | 0 | } else if (useStickyPosition) { |
3367 | 0 | // For position:sticky, the clip needs to be applied both to the sticky |
3368 | 0 | // container item and to the contents. The container item needs the clip |
3369 | 0 | // because a scrolled clip needs to move independently from the sticky |
3370 | 0 | // contents, and the contents need the clip so that they have finite |
3371 | 0 | // clipped bounds with respect to the container item's ASR. The latter is |
3372 | 0 | // a little tricky in the case where the sticky item has both fixed and |
3373 | 0 | // non-fixed descendants, because that means that the sticky container |
3374 | 0 | // item's ASR is the ASR of the fixed descendant. |
3375 | 0 | // For WebRender display list building, though, we still want to know the |
3376 | 0 | // the ASR that the sticky container item would normally have, so we stash |
3377 | 0 | // that on the display item as the "container ASR" (i.e. the normal ASR of |
3378 | 0 | // the container item, excluding the special behaviour induced by fixed |
3379 | 0 | // descendants). |
3380 | 0 | const ActiveScrolledRoot* stickyASR = |
3381 | 0 | ActiveScrolledRoot::PickAncestor(containerItemASR, aBuilder->CurrentActiveScrolledRoot()); |
3382 | 0 | resultList.AppendToTop( |
3383 | 0 | MakeDisplayItem<nsDisplayStickyPosition>(aBuilder, this, &resultList, |
3384 | 0 | stickyASR, aBuilder->CurrentActiveScrolledRoot())); |
3385 | 0 | if (aCreatedContainerItem) { |
3386 | 0 | *aCreatedContainerItem = true; |
3387 | 0 | } |
3388 | 0 | } |
3389 | 0 |
|
3390 | 0 | /* If there's blending, wrap up the list in a blend-mode item. Note |
3391 | 0 | * that opacity can be applied before blending as the blend color is |
3392 | 0 | * not affected by foreground opacity (only background alpha). |
3393 | 0 | */ |
3394 | 0 |
|
3395 | 0 | if (useBlendMode) { |
3396 | 0 | DisplayListClipState::AutoSaveRestore blendModeClipState(aBuilder); |
3397 | 0 | resultList.AppendToTop( |
3398 | 0 | MakeDisplayItem<nsDisplayBlendMode>(aBuilder, this, &resultList, |
3399 | 0 | effects->mMixBlendMode, |
3400 | 0 | containerItemASR)); |
3401 | 0 | if (aCreatedContainerItem) { |
3402 | 0 | *aCreatedContainerItem = true; |
3403 | 0 | } |
3404 | 0 | } |
3405 | 0 |
|
3406 | 0 | CreateOwnLayerIfNeeded(aBuilder, &resultList, aCreatedContainerItem); |
3407 | 0 |
|
3408 | 0 | aList->AppendToTop(&resultList); |
3409 | 0 | } |
3410 | | |
3411 | | static nsDisplayItem* |
3412 | | WrapInWrapList(nsDisplayListBuilder* aBuilder, |
3413 | | nsIFrame* aFrame, nsDisplayList* aList, |
3414 | | const ActiveScrolledRoot* aContainerASR, |
3415 | | bool aCanSkipWrapList = false) |
3416 | 0 | { |
3417 | 0 | nsDisplayItem* item = aList->GetBottom(); |
3418 | 0 | if (!item) { |
3419 | 0 | return nullptr; |
3420 | 0 | } |
3421 | 0 | |
3422 | 0 | if (aCanSkipWrapList) { |
3423 | 0 | MOZ_ASSERT(!item->GetAbove()); |
3424 | 0 | aList->RemoveBottom(); |
3425 | 0 | return item; |
3426 | 0 | } |
3427 | 0 |
|
3428 | 0 | // Clear clip rect for the construction of the items below. Since we're |
3429 | 0 | // clipping all their contents, they themselves don't need to be clipped. |
3430 | 0 | return MakeDisplayItem<nsDisplayWrapList>(aBuilder, aFrame, aList, aContainerASR, true); |
3431 | 0 | } |
3432 | | |
3433 | | /** |
3434 | | * Check if a frame should be visited for building display list. |
3435 | | */ |
3436 | | static bool |
3437 | | DescendIntoChild(nsDisplayListBuilder* aBuilder, nsIFrame *aChild, |
3438 | | const nsRect& aVisible, const nsRect& aDirty) |
3439 | 0 | { |
3440 | 0 | nsIFrame* child = aChild; |
3441 | 0 | const nsRect& dirty = aDirty; |
3442 | 0 |
|
3443 | 0 | if (!(child->GetStateBits() & NS_FRAME_FORCE_DISPLAY_LIST_DESCEND_INTO)) { |
3444 | 0 | // No need to descend into child to catch placeholders for visible |
3445 | 0 | // positioned stuff. So see if we can short-circuit frame traversal here. |
3446 | 0 |
|
3447 | 0 | // We can stop if child's frame subtree's intersection with the |
3448 | 0 | // dirty area is empty. |
3449 | 0 | // If the child is a scrollframe that we want to ignore, then we need |
3450 | 0 | // to descend into it because its scrolled child may intersect the dirty |
3451 | 0 | // area even if the scrollframe itself doesn't. |
3452 | 0 | // There are cases where the "ignore scroll frame" on the builder is not set |
3453 | 0 | // correctly, and so we additionally want to catch cases where the child is |
3454 | 0 | // a root scrollframe and we are ignoring scrolling on the viewport. |
3455 | 0 | nsIPresShell* shell = child->PresShell(); |
3456 | 0 | bool keepDescending = child == aBuilder->GetIgnoreScrollFrame() || |
3457 | 0 | (shell->IgnoringViewportScrolling() && child == shell->GetRootScrollFrame()); |
3458 | 0 | if (!keepDescending) { |
3459 | 0 | nsRect childDirty; |
3460 | 0 | if (!childDirty.IntersectRect(dirty, child->GetVisualOverflowRect()) && |
3461 | 0 | (!child->ForceDescendIntoIfVisible())) { |
3462 | 0 | return false; |
3463 | 0 | } |
3464 | 0 | if (!childDirty.IntersectRect(aVisible, child->GetVisualOverflowRect())) { |
3465 | 0 | return false; |
3466 | 0 | } |
3467 | 0 | // Usually we could set dirty to childDirty now but there's no |
3468 | 0 | // benefit, and it can be confusing. It can especially confuse |
3469 | 0 | // situations where we're going to ignore a scrollframe's clipping; |
3470 | 0 | // we wouldn't want to clip the dirty area to the scrollframe's |
3471 | 0 | // bounds in that case. |
3472 | 0 | } |
3473 | 0 | } |
3474 | 0 | return true; |
3475 | 0 | } |
3476 | | |
3477 | | void |
3478 | | nsIFrame::BuildDisplayListForChild(nsDisplayListBuilder* aBuilder, |
3479 | | nsIFrame* aChild, |
3480 | | const nsDisplayListSet& aLists, |
3481 | 0 | uint32_t aFlags) { |
3482 | 0 | AutoCheckBuilder check(aBuilder); |
3483 | 0 | // If painting is restricted to just the background of the top level frame, |
3484 | 0 | // then we have nothing to do here. |
3485 | 0 | if (aBuilder->IsBackgroundOnly()) |
3486 | 0 | return; |
3487 | 0 | |
3488 | 0 | if (aBuilder->IsForGenerateGlyphMask() || |
3489 | 0 | aBuilder->IsForPaintingSelectionBG()) { |
3490 | 0 | if (!aChild->IsTextFrame() && aChild->IsLeaf()) { |
3491 | 0 | return; |
3492 | 0 | } |
3493 | 0 | } |
3494 | 0 | |
3495 | 0 | nsIFrame* child = aChild; |
3496 | 0 | if (child->HasAnyStateBits( |
3497 | 0 | NS_FRAME_TOO_DEEP_IN_FRAME_TREE | NS_FRAME_IS_NONDISPLAY)) |
3498 | 0 | return; |
3499 | 0 | |
3500 | 0 | aBuilder->RemoveFromWillChangeBudget(child); |
3501 | 0 |
|
3502 | 0 | const bool shortcutPossible = aBuilder->IsPaintingToWindow() && |
3503 | 0 | aBuilder->BuildCompositorHitTestInfo(); |
3504 | 0 |
|
3505 | 0 | const bool doingShortcut = shortcutPossible && |
3506 | 0 | (child->GetStateBits() & NS_FRAME_SIMPLE_DISPLAYLIST) && |
3507 | 0 | // Animations may change the value of |HasOpacity()|. |
3508 | 0 | !(child->GetContent() && |
3509 | 0 | child->GetContent()->MayHaveAnimations()); |
3510 | 0 |
|
3511 | 0 | // dirty rect in child-relative coordinates |
3512 | 0 | NS_ASSERTION(aBuilder->GetCurrentFrame() == this, "Wrong coord space!"); |
3513 | 0 | const nsPoint offset = child->GetOffsetTo(this); |
3514 | 0 | nsRect visible = aBuilder->GetVisibleRect() - offset; |
3515 | 0 | nsRect dirty = aBuilder->GetDirtyRect() - offset; |
3516 | 0 |
|
3517 | 0 | if (doingShortcut) { |
3518 | 0 | // This is the shortcut for frames been handled along the common |
3519 | 0 | // path, the most common one of THE COMMON CASE mentioned later. |
3520 | 0 | MOZ_ASSERT(child->Type() != LayoutFrameType::Placeholder); |
3521 | 0 | MOZ_ASSERT(!aBuilder->GetSelectedFramesOnly() && |
3522 | 0 | !aBuilder->GetIncludeAllOutOfFlows(), |
3523 | 0 | "It should be held for painting to window"); |
3524 | 0 |
|
3525 | 0 | if (!DescendIntoChild(aBuilder, child, visible, dirty)) { |
3526 | 0 | return; |
3527 | 0 | } |
3528 | 0 | |
3529 | 0 | nsDisplayListBuilder::AutoBuildingDisplayList |
3530 | 0 | buildingForChild(aBuilder, child, visible, dirty, false); |
3531 | 0 |
|
3532 | 0 | CheckForApzAwareEventHandlers(aBuilder, child); |
3533 | 0 |
|
3534 | 0 | aBuilder->BuildCompositorHitTestInfoIfNeeded(child, |
3535 | 0 | aLists.BorderBackground(), |
3536 | 0 | false); |
3537 | 0 |
|
3538 | 0 | child->MarkAbsoluteFramesForDisplayList(aBuilder); |
3539 | 0 | aBuilder->AdjustWindowDraggingRegion(child); |
3540 | 0 | aBuilder->Check(); |
3541 | 0 | child->BuildDisplayList(aBuilder, aLists); |
3542 | 0 | aBuilder->Check(); |
3543 | 0 | aBuilder->DisplayCaret(child, aLists.Content()); |
3544 | | #ifdef DEBUG |
3545 | | DisplayDebugBorders(aBuilder, child, aLists); |
3546 | | #endif |
3547 | | return; |
3548 | 0 | } |
3549 | 0 |
|
3550 | 0 | const bool isSVG = child->GetStateBits() & NS_FRAME_SVG_LAYOUT; |
3551 | 0 |
|
3552 | 0 | // It is raised if the control flow strays off the common path. |
3553 | 0 | // The common path is the most common one of THE COMMON CASE |
3554 | 0 | // mentioned later. |
3555 | 0 | bool awayFromCommonPath = false; |
3556 | 0 |
|
3557 | 0 | // true if this is a real or pseudo stacking context |
3558 | 0 | bool pseudoStackingContext = |
3559 | 0 | (aFlags & DISPLAY_CHILD_FORCE_PSEUDO_STACKING_CONTEXT) != 0; |
3560 | 0 |
|
3561 | 0 | if (!pseudoStackingContext && |
3562 | 0 | !isSVG && |
3563 | 0 | (aFlags & DISPLAY_CHILD_INLINE) && |
3564 | 0 | !child->IsFrameOfType(eLineParticipant)) { |
3565 | 0 | // child is a non-inline frame in an inline context, i.e., |
3566 | 0 | // it acts like inline-block or inline-table. Therefore it is a |
3567 | 0 | // pseudo-stacking-context. |
3568 | 0 | pseudoStackingContext = true; |
3569 | 0 | } |
3570 | 0 |
|
3571 | 0 | nsDisplayListBuilder::OutOfFlowDisplayData* savedOutOfFlowData = nullptr; |
3572 | 0 | bool isPlaceholder = false; |
3573 | 0 | if (child->IsPlaceholderFrame()) { |
3574 | 0 | isPlaceholder = true; |
3575 | 0 | nsPlaceholderFrame* placeholder = static_cast<nsPlaceholderFrame*>(child); |
3576 | 0 | child = placeholder->GetOutOfFlowFrame(); |
3577 | 0 | aBuilder->RemoveFromWillChangeBudget(child); |
3578 | 0 | NS_ASSERTION(child, "No out of flow frame?"); |
3579 | 0 | // If 'child' is a pushed float then it's owned by a block that's not an |
3580 | 0 | // ancestor of the placeholder, and it will be painted by that block and |
3581 | 0 | // should not be painted through the placeholder. |
3582 | 0 | if (!child || nsLayoutUtils::IsPopup(child) || |
3583 | 0 | (child->GetStateBits() & NS_FRAME_IS_PUSHED_FLOAT)) |
3584 | 0 | return; |
3585 | 0 | MOZ_ASSERT(child->GetStateBits() & NS_FRAME_OUT_OF_FLOW); |
3586 | 0 | // If the out-of-flow frame is in the top layer, the viewport frame |
3587 | 0 | // will paint it. Skip it here. Note that, only out-of-flow frames |
3588 | 0 | // with this property should be skipped, because non-HTML elements |
3589 | 0 | // may stop their children from being out-of-flow. Those frames |
3590 | 0 | // should still be handled in the normal in-flow path. |
3591 | 0 | if (placeholder->GetStateBits() & PLACEHOLDER_FOR_TOPLAYER) { |
3592 | 0 | return; |
3593 | 0 | } |
3594 | 0 | // Recheck NS_FRAME_TOO_DEEP_IN_FRAME_TREE |
3595 | 0 | if (child->GetStateBits() & NS_FRAME_TOO_DEEP_IN_FRAME_TREE) |
3596 | 0 | return; |
3597 | 0 | savedOutOfFlowData = nsDisplayListBuilder::GetOutOfFlowData(child); |
3598 | 0 | if (savedOutOfFlowData) { |
3599 | 0 | visible = savedOutOfFlowData->GetVisibleRectForFrame(aBuilder, child, &dirty); |
3600 | 0 | } else { |
3601 | 0 | // The out-of-flow frame did not intersect the dirty area. We may still |
3602 | 0 | // need to traverse into it, since it may contain placeholders we need |
3603 | 0 | // to enter to reach other out-of-flow frames that are visible. |
3604 | 0 | visible.SetEmpty(); |
3605 | 0 | dirty.SetEmpty(); |
3606 | 0 | } |
3607 | 0 |
|
3608 | 0 | pseudoStackingContext = true; |
3609 | 0 | } |
3610 | 0 |
|
3611 | 0 | NS_ASSERTION(!child->IsPlaceholderFrame(), |
3612 | 0 | "Should have dealt with placeholders already"); |
3613 | 0 | if (aBuilder->GetSelectedFramesOnly() && |
3614 | 0 | child->IsLeaf() && |
3615 | 0 | !aChild->IsSelected()) { |
3616 | 0 | return; |
3617 | 0 | } |
3618 | 0 | |
3619 | 0 | if (aBuilder->GetIncludeAllOutOfFlows() && isPlaceholder) { |
3620 | 0 | visible = child->GetVisualOverflowRect(); |
3621 | 0 | dirty = child->GetVisualOverflowRect(); |
3622 | 0 | } else if (!DescendIntoChild(aBuilder, child, visible, dirty)) { |
3623 | 0 | return; |
3624 | 0 | } |
3625 | 0 | |
3626 | 0 | // XXX need to have inline-block and inline-table set pseudoStackingContext |
3627 | 0 | |
3628 | 0 | const nsStyleDisplay* ourDisp = StyleDisplay(); |
3629 | 0 | // REVIEW: Taken from nsBoxFrame::Paint |
3630 | 0 | // Don't paint our children if the theme object is a leaf. |
3631 | 0 | if (IsThemed(ourDisp) && |
3632 | 0 | !PresContext()->GetTheme()->WidgetIsContainer(ourDisp->mAppearance)) |
3633 | 0 | return; |
3634 | 0 | |
3635 | 0 | // Since we're now sure that we're adding this frame to the display list |
3636 | 0 | // (which means we're painting it, modulo occlusion), mark it as visible |
3637 | 0 | // within the displayport. |
3638 | 0 | if (aBuilder->IsPaintingToWindow() && child->TrackingVisibility()) { |
3639 | 0 | child->PresShell()->EnsureFrameInApproximatelyVisibleList(child); |
3640 | 0 | awayFromCommonPath = true; |
3641 | 0 | } |
3642 | 0 |
|
3643 | 0 | child->SetBuiltDisplayList(true); |
3644 | 0 |
|
3645 | 0 | // Child is composited if it's transformed, partially transparent, or has |
3646 | 0 | // SVG effects or a blend mode.. |
3647 | 0 | EffectSet* effectSet = EffectSet::GetEffectSet(child); |
3648 | 0 | const nsStyleDisplay* disp = child->StyleDisplay(); |
3649 | 0 | const nsStyleEffects* effects = child->StyleEffects(); |
3650 | 0 | const nsStylePosition* pos = child->StylePosition(); |
3651 | 0 |
|
3652 | 0 | const bool isPositioned = |
3653 | 0 | disp->IsAbsPosContainingBlock(child); |
3654 | 0 |
|
3655 | 0 | const bool isStackingContext = |
3656 | 0 | child->IsStackingContext(effectSet, disp, pos, effects, isPositioned) || |
3657 | 0 | (aFlags & DISPLAY_CHILD_FORCE_STACKING_CONTEXT); |
3658 | 0 |
|
3659 | 0 | if (pseudoStackingContext || isStackingContext || isPositioned || |
3660 | 0 | (!isSVG && disp->IsFloating(child)) || |
3661 | 0 | (isSVG && (effects->mClipFlags & NS_STYLE_CLIP_RECT) && |
3662 | 0 | IsSVGContentWithCSSClip(child))) { |
3663 | 0 | pseudoStackingContext = true; |
3664 | 0 | awayFromCommonPath = true; |
3665 | 0 | } |
3666 | 0 |
|
3667 | 0 | NS_ASSERTION(!isStackingContext || pseudoStackingContext, |
3668 | 0 | "Stacking contexts must also be pseudo-stacking-contexts"); |
3669 | 0 |
|
3670 | 0 | nsDisplayListBuilder::AutoBuildingDisplayList |
3671 | 0 | buildingForChild(aBuilder, child, visible, dirty, pseudoStackingContext); |
3672 | 0 | DisplayListClipState::AutoClipMultiple clipState(aBuilder); |
3673 | 0 | nsDisplayListBuilder::AutoCurrentActiveScrolledRootSetter asrSetter(aBuilder); |
3674 | 0 | CheckForApzAwareEventHandlers(aBuilder, child); |
3675 | 0 |
|
3676 | 0 | if (savedOutOfFlowData) { |
3677 | 0 | aBuilder->SetBuildingInvisibleItems(false); |
3678 | 0 |
|
3679 | 0 | clipState.SetClipChainForContainingBlockDescendants( |
3680 | 0 | savedOutOfFlowData->mContainingBlockClipChain); |
3681 | 0 | asrSetter.SetCurrentActiveScrolledRoot( |
3682 | 0 | savedOutOfFlowData->mContainingBlockActiveScrolledRoot); |
3683 | 0 | MOZ_ASSERT(awayFromCommonPath, "It is impossible when savedOutOfFlowData is true"); |
3684 | 0 | } else if (GetStateBits() & NS_FRAME_FORCE_DISPLAY_LIST_DESCEND_INTO && |
3685 | 0 | isPlaceholder) { |
3686 | 0 | NS_ASSERTION(visible.IsEmpty(), "should have empty visible rect"); |
3687 | 0 | // Every item we build from now until we descent into an out of flow that |
3688 | 0 | // does have saved out of flow data should be invisible. This state gets |
3689 | 0 | // restored when AutoBuildingDisplayList gets out of scope. |
3690 | 0 | aBuilder->SetBuildingInvisibleItems(true); |
3691 | 0 |
|
3692 | 0 | // If we have nested out-of-flow frames and the outer one isn't visible |
3693 | 0 | // then we won't have stored clip data for it. We can just clear the clip |
3694 | 0 | // instead since we know we won't render anything, and the inner out-of-flow |
3695 | 0 | // frame will setup the correct clip for itself. |
3696 | 0 | clipState.SetClipChainForContainingBlockDescendants(nullptr); |
3697 | 0 | } |
3698 | 0 |
|
3699 | 0 | // Setup clipping for the parent's overflow:-moz-hidden-unscrollable, |
3700 | 0 | // or overflow:hidden on elements that don't support scrolling (and therefore |
3701 | 0 | // don't create nsHTML/XULScrollFrame). This clipping needs to not clip |
3702 | 0 | // anything directly rendered by the parent, only the rendering of its |
3703 | 0 | // children. |
3704 | 0 | // Don't use overflowClip to restrict the dirty rect, since some of the |
3705 | 0 | // descendants may not be clipped by it. Even if we end up with unnecessary |
3706 | 0 | // display items, they'll be pruned during ComputeVisibility. |
3707 | 0 | nsIFrame* parent = child->GetParent(); |
3708 | 0 | const nsStyleDisplay* parentDisp = |
3709 | 0 | parent == this ? ourDisp : parent->StyleDisplay(); |
3710 | 0 | if (ApplyOverflowClipping(aBuilder, parent, parentDisp, clipState)) { |
3711 | 0 | awayFromCommonPath = true; |
3712 | 0 | } |
3713 | 0 |
|
3714 | 0 | nsDisplayList list; |
3715 | 0 | nsDisplayList extraPositionedDescendants; |
3716 | 0 | const ActiveScrolledRoot* wrapListASR; |
3717 | 0 | bool canSkipWrapList = false; |
3718 | 0 | if (isStackingContext) { |
3719 | 0 | if (effects->mMixBlendMode != NS_STYLE_BLEND_NORMAL) { |
3720 | 0 | aBuilder->SetContainsBlendMode(true); |
3721 | 0 | } |
3722 | 0 | // True stacking context. |
3723 | 0 | // For stacking contexts, BuildDisplayListForStackingContext handles |
3724 | 0 | // clipping and MarkAbsoluteFramesForDisplayList. |
3725 | 0 | nsDisplayListBuilder::AutoContainerASRTracker contASRTracker(aBuilder); |
3726 | 0 | child->BuildDisplayListForStackingContext(aBuilder, &list, &canSkipWrapList); |
3727 | 0 | wrapListASR = contASRTracker.GetContainerASR(); |
3728 | 0 | if (aBuilder->DisplayCaret(child, &list)) { |
3729 | 0 | canSkipWrapList = false; |
3730 | 0 | } |
3731 | 0 | } else { |
3732 | 0 | Maybe<nsRect> clipPropClip = |
3733 | 0 | child->GetClipPropClipRect(disp, effects, child->GetSize()); |
3734 | 0 | if (clipPropClip) { |
3735 | 0 | aBuilder->IntersectVisibleRect(*clipPropClip); |
3736 | 0 | aBuilder->IntersectDirtyRect(*clipPropClip); |
3737 | 0 | clipState.ClipContentDescendants( |
3738 | 0 | *clipPropClip + aBuilder->ToReferenceFrame(child)); |
3739 | 0 | awayFromCommonPath = true; |
3740 | 0 | } |
3741 | 0 |
|
3742 | 0 | child->MarkAbsoluteFramesForDisplayList(aBuilder); |
3743 | 0 |
|
3744 | 0 | const bool differentAGR = |
3745 | 0 | buildingForChild.IsAnimatedGeometryRoot() || isPositioned; |
3746 | 0 |
|
3747 | 0 | if (!awayFromCommonPath && shortcutPossible && |
3748 | 0 | !differentAGR && !buildingForChild.MaybeAnimatedGeometryRoot()) { |
3749 | 0 | // The shortcut is available for the child for next time. |
3750 | 0 | child->AddStateBits(NS_FRAME_SIMPLE_DISPLAYLIST); |
3751 | 0 | } |
3752 | 0 |
|
3753 | 0 | if (!pseudoStackingContext) { |
3754 | 0 | // THIS IS THE COMMON CASE. |
3755 | 0 | // Not a pseudo or real stacking context. Do the simple thing and |
3756 | 0 | // return early. |
3757 | 0 |
|
3758 | 0 | aBuilder->BuildCompositorHitTestInfoIfNeeded(child, |
3759 | 0 | aLists.BorderBackground(), |
3760 | 0 | differentAGR); |
3761 | 0 |
|
3762 | 0 | aBuilder->AdjustWindowDraggingRegion(child); |
3763 | 0 | aBuilder->Check(); |
3764 | 0 | child->BuildDisplayList(aBuilder, aLists); |
3765 | 0 | aBuilder->Check(); |
3766 | 0 | aBuilder->DisplayCaret(child, aLists.Content()); |
3767 | | #ifdef DEBUG |
3768 | | DisplayDebugBorders(aBuilder, child, aLists); |
3769 | | #endif |
3770 | | return; |
3771 | 0 | } |
3772 | 0 |
|
3773 | 0 | // A pseudo-stacking context (e.g., a positioned element with z-index auto). |
3774 | 0 | // We allow positioned descendants of the child to escape to our parent |
3775 | 0 | // stacking context's positioned descendant list, because they might be |
3776 | 0 | // z-index:non-auto |
3777 | 0 | nsDisplayListCollection pseudoStack(aBuilder); |
3778 | 0 |
|
3779 | 0 | aBuilder->BuildCompositorHitTestInfoIfNeeded(child, |
3780 | 0 | pseudoStack.BorderBackground(), |
3781 | 0 | differentAGR); |
3782 | 0 |
|
3783 | 0 | aBuilder->AdjustWindowDraggingRegion(child); |
3784 | 0 | nsDisplayListBuilder::AutoContainerASRTracker contASRTracker(aBuilder); |
3785 | 0 | aBuilder->Check(); |
3786 | 0 | child->BuildDisplayList(aBuilder, pseudoStack); |
3787 | 0 | aBuilder->Check(); |
3788 | 0 | if (aBuilder->DisplayCaret(child, pseudoStack.Content())) { |
3789 | 0 | canSkipWrapList = false; |
3790 | 0 | } |
3791 | 0 | wrapListASR = contASRTracker.GetContainerASR(); |
3792 | 0 |
|
3793 | 0 | list.AppendToTop(pseudoStack.BorderBackground()); |
3794 | 0 | list.AppendToTop(pseudoStack.BlockBorderBackgrounds()); |
3795 | 0 | list.AppendToTop(pseudoStack.Floats()); |
3796 | 0 | list.AppendToTop(pseudoStack.Content()); |
3797 | 0 | list.AppendToTop(pseudoStack.Outlines()); |
3798 | 0 | extraPositionedDescendants.AppendToTop(pseudoStack.PositionedDescendants()); |
3799 | | #ifdef DEBUG |
3800 | | DisplayDebugBorders(aBuilder, child, aLists); |
3801 | | #endif |
3802 | | } |
3803 | 0 |
|
3804 | 0 | buildingForChild.RestoreBuildingInvisibleItemsValue(); |
3805 | 0 |
|
3806 | 0 | if (isPositioned || isStackingContext || |
3807 | 0 | (aFlags & DISPLAY_CHILD_FORCE_STACKING_CONTEXT)) { |
3808 | 0 | // Genuine stacking contexts, and positioned pseudo-stacking-contexts, |
3809 | 0 | // go in this level. |
3810 | 0 | if (!list.IsEmpty()) { |
3811 | 0 | nsDisplayItem* item = WrapInWrapList(aBuilder, child, &list, wrapListASR, canSkipWrapList); |
3812 | 0 | if (isSVG) { |
3813 | 0 | aLists.Content()->AppendToTop(item); |
3814 | 0 | } else { |
3815 | 0 | aLists.PositionedDescendants()->AppendToTop(item); |
3816 | 0 | } |
3817 | 0 | } |
3818 | 0 | } else if (!isSVG && disp->IsFloating(child)) { |
3819 | 0 | if (!list.IsEmpty()) { |
3820 | 0 | aLists.Floats()->AppendToTop(WrapInWrapList(aBuilder, child, &list, wrapListASR)); |
3821 | 0 | } |
3822 | 0 | } else { |
3823 | 0 | aLists.Content()->AppendToTop(&list); |
3824 | 0 | } |
3825 | 0 | // We delay placing the positioned descendants of positioned frames to here, |
3826 | 0 | // because in the absence of z-index this is the correct order for them. |
3827 | 0 | // This doesn't affect correctness because the positioned descendants list |
3828 | 0 | // is sorted by z-order and content in BuildDisplayListForStackingContext, |
3829 | 0 | // but it means that sort routine needs to do less work. |
3830 | 0 | aLists.PositionedDescendants()->AppendToTop(&extraPositionedDescendants); |
3831 | 0 | } |
3832 | | |
3833 | | void |
3834 | | nsIFrame::MarkAbsoluteFramesForDisplayList(nsDisplayListBuilder* aBuilder) |
3835 | 0 | { |
3836 | 0 | if (IsAbsoluteContainer()) { |
3837 | 0 | aBuilder->MarkFramesForDisplayList(this, GetAbsoluteContainingBlock()->GetChildList()); |
3838 | 0 | } |
3839 | 0 | } |
3840 | | |
3841 | | nsresult |
3842 | | nsFrame::GetContentForEvent(WidgetEvent* aEvent, |
3843 | | nsIContent** aContent) |
3844 | 0 | { |
3845 | 0 | nsIFrame* f = nsLayoutUtils::GetNonGeneratedAncestor(this); |
3846 | 0 | *aContent = f->GetContent(); |
3847 | 0 | NS_IF_ADDREF(*aContent); |
3848 | 0 | return NS_OK; |
3849 | 0 | } |
3850 | | |
3851 | | void |
3852 | | nsFrame::FireDOMEvent(const nsAString& aDOMEventName, nsIContent *aContent) |
3853 | 0 | { |
3854 | 0 | nsIContent* target = aContent ? aContent : GetContent(); |
3855 | 0 |
|
3856 | 0 | if (target) { |
3857 | 0 | RefPtr<AsyncEventDispatcher> asyncDispatcher = |
3858 | 0 | new AsyncEventDispatcher(target, |
3859 | 0 | aDOMEventName, |
3860 | 0 | CanBubble::eYes, |
3861 | 0 | ChromeOnlyDispatch::eNo); |
3862 | 0 | DebugOnly<nsresult> rv = asyncDispatcher->PostDOMEvent(); |
3863 | 0 | NS_ASSERTION(NS_SUCCEEDED(rv), "AsyncEventDispatcher failed to dispatch"); |
3864 | 0 | } |
3865 | 0 | } |
3866 | | |
3867 | | nsresult |
3868 | | nsFrame::HandleEvent(nsPresContext* aPresContext, |
3869 | | WidgetGUIEvent* aEvent, |
3870 | | nsEventStatus* aEventStatus) |
3871 | 0 | { |
3872 | 0 |
|
3873 | 0 | if (aEvent->mMessage == eMouseMove) { |
3874 | 0 | // XXX If the second argument of HandleDrag() is WidgetMouseEvent, |
3875 | 0 | // the implementation becomes simpler. |
3876 | 0 | return HandleDrag(aPresContext, aEvent, aEventStatus); |
3877 | 0 | } |
3878 | 0 | |
3879 | 0 | if ((aEvent->mClass == eMouseEventClass && |
3880 | 0 | aEvent->AsMouseEvent()->button == WidgetMouseEvent::eLeftButton) || |
3881 | 0 | aEvent->mClass == eTouchEventClass) { |
3882 | 0 | if (aEvent->mMessage == eMouseDown || aEvent->mMessage == eTouchStart) { |
3883 | 0 | HandlePress(aPresContext, aEvent, aEventStatus); |
3884 | 0 | } else if (aEvent->mMessage == eMouseUp || aEvent->mMessage == eTouchEnd) { |
3885 | 0 | HandleRelease(aPresContext, aEvent, aEventStatus); |
3886 | 0 | } |
3887 | 0 | } |
3888 | 0 | return NS_OK; |
3889 | 0 | } |
3890 | | |
3891 | | nsresult |
3892 | | nsFrame::GetDataForTableSelection(const nsFrameSelection* aFrameSelection, |
3893 | | nsIPresShell* aPresShell, |
3894 | | WidgetMouseEvent* aMouseEvent, |
3895 | | nsIContent** aParentContent, |
3896 | | int32_t* aContentOffset, |
3897 | | TableSelection* aTarget) |
3898 | 0 | { |
3899 | 0 | if (!aFrameSelection || !aPresShell || !aMouseEvent || !aParentContent || !aContentOffset || !aTarget) |
3900 | 0 | return NS_ERROR_NULL_POINTER; |
3901 | 0 | |
3902 | 0 | *aParentContent = nullptr; |
3903 | 0 | *aContentOffset = 0; |
3904 | 0 | *aTarget = TableSelection::None; |
3905 | 0 |
|
3906 | 0 | int16_t displaySelection = aPresShell->GetSelectionFlags(); |
3907 | 0 |
|
3908 | 0 | bool selectingTableCells = aFrameSelection->GetTableCellSelection(); |
3909 | 0 |
|
3910 | 0 | // DISPLAY_ALL means we're in an editor. |
3911 | 0 | // If already in cell selection mode, |
3912 | 0 | // continue selecting with mouse drag or end on mouse up, |
3913 | 0 | // or when using shift key to extend block of cells |
3914 | 0 | // (Mouse down does normal selection unless Ctrl/Cmd is pressed) |
3915 | 0 | bool doTableSelection = |
3916 | 0 | displaySelection == nsISelectionDisplay::DISPLAY_ALL && selectingTableCells && |
3917 | 0 | (aMouseEvent->mMessage == eMouseMove || |
3918 | 0 | (aMouseEvent->mMessage == eMouseUp && |
3919 | 0 | aMouseEvent->button == WidgetMouseEvent::eLeftButton) || |
3920 | 0 | aMouseEvent->IsShift()); |
3921 | 0 |
|
3922 | 0 | if (!doTableSelection) |
3923 | 0 | { |
3924 | 0 | // In Browser, special 'table selection' key must be pressed for table selection |
3925 | 0 | // or when just Shift is pressed and we're already in table/cell selection mode |
3926 | | #ifdef XP_MACOSX |
3927 | | doTableSelection = aMouseEvent->IsMeta() || (aMouseEvent->IsShift() && selectingTableCells); |
3928 | | #else |
3929 | 0 | doTableSelection = aMouseEvent->IsControl() || (aMouseEvent->IsShift() && selectingTableCells); |
3930 | 0 | #endif |
3931 | 0 | } |
3932 | 0 | if (!doTableSelection) |
3933 | 0 | return NS_OK; |
3934 | 0 | |
3935 | 0 | // Get the cell frame or table frame (or parent) of the current content node |
3936 | 0 | nsIFrame *frame = this; |
3937 | 0 | bool foundCell = false; |
3938 | 0 | bool foundTable = false; |
3939 | 0 |
|
3940 | 0 | // Get the limiting node to stop parent frame search |
3941 | 0 | nsIContent* limiter = aFrameSelection->GetLimiter(); |
3942 | 0 |
|
3943 | 0 | // If our content node is an ancestor of the limiting node, |
3944 | 0 | // we should stop the search right now. |
3945 | 0 | if (limiter && nsContentUtils::ContentIsDescendantOf(limiter, GetContent())) |
3946 | 0 | return NS_OK; |
3947 | 0 | |
3948 | 0 | //We don't initiate row/col selection from here now, |
3949 | 0 | // but we may in future |
3950 | 0 | //bool selectColumn = false; |
3951 | 0 | //bool selectRow = false; |
3952 | 0 | |
3953 | 0 | while (frame) |
3954 | 0 | { |
3955 | 0 | // Check for a table cell by querying to a known CellFrame interface |
3956 | 0 | nsITableCellLayout *cellElement = do_QueryFrame(frame); |
3957 | 0 | if (cellElement) |
3958 | 0 | { |
3959 | 0 | foundCell = true; |
3960 | 0 | //TODO: If we want to use proximity to top or left border |
3961 | 0 | // for row and column selection, this is the place to do it |
3962 | 0 | break; |
3963 | 0 | } |
3964 | 0 | else |
3965 | 0 | { |
3966 | 0 | // If not a cell, check for table |
3967 | 0 | // This will happen when starting frame is the table or child of a table, |
3968 | 0 | // such as a row (we were inbetween cells or in table border) |
3969 | 0 | nsTableWrapperFrame *tableFrame = do_QueryFrame(frame); |
3970 | 0 | if (tableFrame) |
3971 | 0 | { |
3972 | 0 | foundTable = true; |
3973 | 0 | //TODO: How can we select row when along left table edge |
3974 | 0 | // or select column when along top edge? |
3975 | 0 | break; |
3976 | 0 | } else { |
3977 | 0 | frame = frame->GetParent(); |
3978 | 0 | // Stop if we have hit the selection's limiting content node |
3979 | 0 | if (frame && frame->GetContent() == limiter) |
3980 | 0 | break; |
3981 | 0 | } |
3982 | 0 | } |
3983 | 0 | } |
3984 | 0 | // We aren't in a cell or table |
3985 | 0 | if (!foundCell && !foundTable) return NS_OK; |
3986 | 0 | |
3987 | 0 | nsIContent* tableOrCellContent = frame->GetContent(); |
3988 | 0 | if (!tableOrCellContent) return NS_ERROR_FAILURE; |
3989 | 0 | |
3990 | 0 | nsCOMPtr<nsIContent> parentContent = tableOrCellContent->GetParent(); |
3991 | 0 | if (!parentContent) return NS_ERROR_FAILURE; |
3992 | 0 | |
3993 | 0 | int32_t offset = parentContent->ComputeIndexOf(tableOrCellContent); |
3994 | 0 | // Not likely? |
3995 | 0 | if (offset < 0) return NS_ERROR_FAILURE; |
3996 | 0 | |
3997 | 0 | // Everything is OK -- set the return values |
3998 | 0 | parentContent.forget(aParentContent); |
3999 | 0 |
|
4000 | 0 | *aContentOffset = offset; |
4001 | 0 |
|
4002 | | #if 0 |
4003 | | if (selectRow) |
4004 | | *aTarget = TableSelection::Row; |
4005 | | else if (selectColumn) |
4006 | | *aTarget = TableSelection::Column; |
4007 | | else |
4008 | | #endif |
4009 | 0 | if (foundCell) |
4010 | 0 | *aTarget = TableSelection::Cell; |
4011 | 0 | else if (foundTable) |
4012 | 0 | *aTarget = TableSelection::Table; |
4013 | 0 |
|
4014 | 0 | return NS_OK; |
4015 | 0 | } |
4016 | | |
4017 | | bool |
4018 | | nsIFrame::IsSelectable(StyleUserSelect* aSelectStyle) const |
4019 | 0 | { |
4020 | 0 | // it's ok if aSelectStyle is null |
4021 | 0 |
|
4022 | 0 | // Like 'visibility', we must check all the parents: if a parent |
4023 | 0 | // is not selectable, none of its children is selectable. |
4024 | 0 | // |
4025 | 0 | // The -moz-all value acts similarly: if a frame has 'user-select:-moz-all', |
4026 | 0 | // all its children are selectable, even those with 'user-select:none'. |
4027 | 0 | // |
4028 | 0 | // As a result, if 'none' and '-moz-all' are not present in the frame hierarchy, |
4029 | 0 | // aSelectStyle returns the first style that is not AUTO. If these values |
4030 | 0 | // are present in the frame hierarchy, aSelectStyle returns the style of the |
4031 | 0 | // topmost parent that has either 'none' or '-moz-all'. |
4032 | 0 | // |
4033 | 0 | // The -moz-text value acts as a way to override an ancestor's all/-moz-all value. |
4034 | 0 | // |
4035 | 0 | // For instance, if the frame hierarchy is: |
4036 | 0 | // AUTO -> _MOZ_ALL -> NONE -> TEXT, the returned value is ALL |
4037 | 0 | // AUTO -> _MOZ_ALL -> NONE -> _MOZ_TEXT, the returned value is TEXT. |
4038 | 0 | // TEXT -> NONE -> AUTO -> _MOZ_ALL, the returned value is TEXT |
4039 | 0 | // _MOZ_ALL -> TEXT -> AUTO -> AUTO, the returned value is ALL |
4040 | 0 | // _MOZ_ALL -> _MOZ_TEXT -> AUTO -> AUTO, the returned value is TEXT. |
4041 | 0 | // AUTO -> CELL -> TEXT -> AUTO, the returned value is TEXT |
4042 | 0 | // |
4043 | 0 | StyleUserSelect selectStyle = StyleUserSelect::Auto; |
4044 | 0 | nsIFrame* frame = const_cast<nsIFrame*>(this); |
4045 | 0 | bool containsEditable = false; |
4046 | 0 |
|
4047 | 0 | while (frame) { |
4048 | 0 | const nsStyleUIReset* userinterface = frame->StyleUIReset(); |
4049 | 0 | switch (userinterface->mUserSelect) { |
4050 | 0 | case StyleUserSelect::All: |
4051 | 0 | case StyleUserSelect::MozAll: |
4052 | 0 | { |
4053 | 0 | // override the previous values |
4054 | 0 | if (selectStyle != StyleUserSelect::MozText) { |
4055 | 0 | selectStyle = userinterface->mUserSelect; |
4056 | 0 | } |
4057 | 0 | nsIContent* frameContent = frame->GetContent(); |
4058 | 0 | containsEditable = frameContent && |
4059 | 0 | frameContent->EditableDescendantCount() > 0; |
4060 | 0 | break; |
4061 | 0 | } |
4062 | 0 | default: |
4063 | 0 | // otherwise return the first value which is not 'auto' |
4064 | 0 | if (selectStyle == StyleUserSelect::Auto) { |
4065 | 0 | selectStyle = userinterface->mUserSelect; |
4066 | 0 | } |
4067 | 0 | break; |
4068 | 0 | } |
4069 | 0 | frame = nsLayoutUtils::GetParentOrPlaceholderFor(frame); |
4070 | 0 | } |
4071 | 0 |
|
4072 | 0 | // convert internal values to standard values |
4073 | 0 | if (selectStyle == StyleUserSelect::Auto || |
4074 | 0 | selectStyle == StyleUserSelect::MozText) { |
4075 | 0 | selectStyle = StyleUserSelect::Text; |
4076 | 0 | } else if (selectStyle == StyleUserSelect::MozAll) { |
4077 | 0 | selectStyle = StyleUserSelect::All; |
4078 | 0 | } |
4079 | 0 |
|
4080 | 0 | // If user tries to select all of a non-editable content, |
4081 | 0 | // prevent selection if it contains editable content. |
4082 | 0 | bool allowSelection = true; |
4083 | 0 | if (selectStyle == StyleUserSelect::All) { |
4084 | 0 | allowSelection = !containsEditable; |
4085 | 0 | } |
4086 | 0 |
|
4087 | 0 | // return stuff |
4088 | 0 | if (aSelectStyle) { |
4089 | 0 | *aSelectStyle = selectStyle; |
4090 | 0 | } |
4091 | 0 |
|
4092 | 0 | return !(mState & NS_FRAME_GENERATED_CONTENT) && |
4093 | 0 | allowSelection && |
4094 | 0 | selectStyle != StyleUserSelect::None; |
4095 | 0 | } |
4096 | | |
4097 | | /** |
4098 | | * Handles the Mouse Press Event for the frame |
4099 | | */ |
4100 | | NS_IMETHODIMP |
4101 | | nsFrame::HandlePress(nsPresContext* aPresContext, |
4102 | | WidgetGUIEvent* aEvent, |
4103 | | nsEventStatus* aEventStatus) |
4104 | 0 | { |
4105 | 0 | NS_ENSURE_ARG_POINTER(aEventStatus); |
4106 | 0 | if (nsEventStatus_eConsumeNoDefault == *aEventStatus) { |
4107 | 0 | return NS_OK; |
4108 | 0 | } |
4109 | 0 | |
4110 | 0 | NS_ENSURE_ARG_POINTER(aEvent); |
4111 | 0 | if (aEvent->mClass == eTouchEventClass) { |
4112 | 0 | return NS_OK; |
4113 | 0 | } |
4114 | 0 | |
4115 | 0 | //We often get out of sync state issues with mousedown events that |
4116 | 0 | //get interrupted by alerts/dialogs. |
4117 | 0 | //Check with the ESM to see if we should process this one |
4118 | 0 | if (!aPresContext->EventStateManager()->EventStatusOK(aEvent)) |
4119 | 0 | return NS_OK; |
4120 | 0 | |
4121 | 0 | nsIPresShell *shell = aPresContext->GetPresShell(); |
4122 | 0 | if (!shell) |
4123 | 0 | return NS_ERROR_FAILURE; |
4124 | 0 | |
4125 | 0 | // if we are in Navigator and the click is in a draggable node, we don't want |
4126 | 0 | // to start selection because we don't want to interfere with a potential |
4127 | 0 | // drag of said node and steal all its glory. |
4128 | 0 | int16_t isEditor = shell->GetSelectionFlags(); |
4129 | 0 | //weaaak. only the editor can display frame selection not just text and images |
4130 | 0 | isEditor = isEditor == nsISelectionDisplay::DISPLAY_ALL; |
4131 | 0 |
|
4132 | 0 | WidgetMouseEvent* mouseEvent = aEvent->AsMouseEvent(); |
4133 | 0 |
|
4134 | 0 | if (!mouseEvent->IsAlt()) { |
4135 | 0 | for (nsIContent* content = mContent; content; |
4136 | 0 | content = content->GetParent()) { |
4137 | 0 | if (nsContentUtils::ContentIsDraggable(content) && |
4138 | 0 | !content->IsEditable()) { |
4139 | 0 | // coordinate stuff is the fix for bug #55921 |
4140 | 0 | if ((mRect - GetPosition()).Contains( |
4141 | 0 | nsLayoutUtils::GetEventCoordinatesRelativeTo(mouseEvent, this))) { |
4142 | 0 | return NS_OK; |
4143 | 0 | } |
4144 | 0 | } |
4145 | 0 | } |
4146 | 0 | } |
4147 | 0 |
|
4148 | 0 | // check whether style allows selection |
4149 | 0 | // if not, don't tell selection the mouse event even occurred. |
4150 | 0 | StyleUserSelect selectStyle; |
4151 | 0 | // check for select: none |
4152 | 0 | if (!IsSelectable(&selectStyle)) { |
4153 | 0 | return NS_OK; |
4154 | 0 | } |
4155 | 0 | |
4156 | 0 | // When implementing StyleUserSelect::Element, StyleUserSelect::Elements and |
4157 | 0 | // StyleUserSelect::Toggle, need to change this logic |
4158 | 0 | bool useFrameSelection = (selectStyle == StyleUserSelect::Text); |
4159 | 0 |
|
4160 | 0 | // If the mouse is dragged outside the nearest enclosing scrollable area |
4161 | 0 | // while making a selection, the area will be scrolled. To do this, capture |
4162 | 0 | // the mouse on the nearest scrollable frame. If there isn't a scrollable |
4163 | 0 | // frame, or something else is already capturing the mouse, there's no |
4164 | 0 | // reason to capture. |
4165 | 0 | if (!nsIPresShell::GetCapturingContent()) { |
4166 | 0 | nsIScrollableFrame* scrollFrame = |
4167 | 0 | nsLayoutUtils::GetNearestScrollableFrame(this, |
4168 | 0 | nsLayoutUtils::SCROLLABLE_SAME_DOC | |
4169 | 0 | nsLayoutUtils::SCROLLABLE_INCLUDE_HIDDEN); |
4170 | 0 | if (scrollFrame) { |
4171 | 0 | nsIFrame* capturingFrame = do_QueryFrame(scrollFrame); |
4172 | 0 | nsIPresShell::SetCapturingContent(capturingFrame->GetContent(), |
4173 | 0 | CAPTURE_IGNOREALLOWED); |
4174 | 0 | } |
4175 | 0 | } |
4176 | 0 |
|
4177 | 0 | // XXX This is screwy; it really should use the selection frame, not the |
4178 | 0 | // event frame |
4179 | 0 | const nsFrameSelection* frameselection = nullptr; |
4180 | 0 | if (useFrameSelection) |
4181 | 0 | frameselection = GetConstFrameSelection(); |
4182 | 0 | else |
4183 | 0 | frameselection = shell->ConstFrameSelection(); |
4184 | 0 |
|
4185 | 0 | if (!frameselection || frameselection->GetDisplaySelection() == nsISelectionController::SELECTION_OFF) |
4186 | 0 | return NS_OK;//nothing to do we cannot affect selection from here |
4187 | 0 | |
4188 | | #ifdef XP_MACOSX |
4189 | | if (mouseEvent->IsControl()) |
4190 | | return NS_OK;//short circuit. hard coded for mac due to time restraints. |
4191 | | bool control = mouseEvent->IsMeta(); |
4192 | | #else |
4193 | 0 | bool control = mouseEvent->IsControl(); |
4194 | 0 | #endif |
4195 | 0 |
|
4196 | 0 | RefPtr<nsFrameSelection> fc = const_cast<nsFrameSelection*>(frameselection); |
4197 | 0 | if (mouseEvent->mClickCount > 1) { |
4198 | 0 | // These methods aren't const but can't actually delete anything, |
4199 | 0 | // so no need for AutoWeakFrame. |
4200 | 0 | fc->SetDragState(true); |
4201 | 0 | fc->SetMouseDoubleDown(true); |
4202 | 0 | return HandleMultiplePress(aPresContext, mouseEvent, aEventStatus, control); |
4203 | 0 | } |
4204 | 0 | |
4205 | 0 | nsPoint pt = nsLayoutUtils::GetEventCoordinatesRelativeTo(mouseEvent, this); |
4206 | 0 | ContentOffsets offsets = GetContentOffsetsFromPoint(pt, SKIP_HIDDEN); |
4207 | 0 |
|
4208 | 0 | if (!offsets.content) |
4209 | 0 | return NS_ERROR_FAILURE; |
4210 | 0 | |
4211 | 0 | // Let Ctrl/Cmd+mouse down do table selection instead of drag initiation |
4212 | 0 | nsCOMPtr<nsIContent>parentContent; |
4213 | 0 | int32_t contentOffset; |
4214 | 0 | TableSelection target; |
4215 | 0 | nsresult rv; |
4216 | 0 | rv = GetDataForTableSelection(frameselection, shell, mouseEvent, |
4217 | 0 | getter_AddRefs(parentContent), &contentOffset, |
4218 | 0 | &target); |
4219 | 0 | if (NS_SUCCEEDED(rv) && parentContent) |
4220 | 0 | { |
4221 | 0 | fc->SetDragState(true); |
4222 | 0 | return fc->HandleTableSelection(parentContent, contentOffset, target, |
4223 | 0 | mouseEvent); |
4224 | 0 | } |
4225 | 0 | |
4226 | 0 | fc->SetDelayedCaretData(0); |
4227 | 0 |
|
4228 | 0 | // Check if any part of this frame is selected, and if the |
4229 | 0 | // user clicked inside the selected region. If so, we delay |
4230 | 0 | // starting a new selection since the user may be trying to |
4231 | 0 | // drag the selected region to some other app. |
4232 | 0 |
|
4233 | 0 | if (GetContent() && GetContent()->IsSelectionDescendant()) |
4234 | 0 | { |
4235 | 0 | bool inSelection = false; |
4236 | 0 | UniquePtr<SelectionDetails> details |
4237 | 0 | = frameselection->LookUpSelection(offsets.content, 0, |
4238 | 0 | offsets.EndOffset(), false); |
4239 | 0 |
|
4240 | 0 | // |
4241 | 0 | // If there are any details, check to see if the user clicked |
4242 | 0 | // within any selected region of the frame. |
4243 | 0 | // |
4244 | 0 |
|
4245 | 0 | for (SelectionDetails* curDetail = details.get(); |
4246 | 0 | curDetail; |
4247 | 0 | curDetail = curDetail->mNext.get()) { |
4248 | 0 | // |
4249 | 0 | // If the user clicked inside a selection, then just |
4250 | 0 | // return without doing anything. We will handle placing |
4251 | 0 | // the caret later on when the mouse is released. We ignore |
4252 | 0 | // the spellcheck, find and url formatting selections. |
4253 | 0 | // |
4254 | 0 | if (curDetail->mSelectionType != SelectionType::eSpellCheck && |
4255 | 0 | curDetail->mSelectionType != SelectionType::eFind && |
4256 | 0 | curDetail->mSelectionType != SelectionType::eURLSecondary && |
4257 | 0 | curDetail->mSelectionType != SelectionType::eURLStrikeout && |
4258 | 0 | curDetail->mStart <= offsets.StartOffset() && |
4259 | 0 | offsets.EndOffset() <= curDetail->mEnd) |
4260 | 0 | { |
4261 | 0 | inSelection = true; |
4262 | 0 | } |
4263 | 0 | } |
4264 | 0 |
|
4265 | 0 | if (inSelection) { |
4266 | 0 | fc->SetDragState(false); |
4267 | 0 | fc->SetDelayedCaretData(mouseEvent); |
4268 | 0 | return NS_OK; |
4269 | 0 | } |
4270 | 0 | } |
4271 | 0 | |
4272 | 0 | fc->SetDragState(true); |
4273 | 0 |
|
4274 | 0 | // Do not touch any nsFrame members after this point without adding |
4275 | 0 | // weakFrame checks. |
4276 | 0 | rv = fc->HandleClick(offsets.content, offsets.StartOffset(), |
4277 | 0 | offsets.EndOffset(), mouseEvent->IsShift(), control, |
4278 | 0 | offsets.associate); |
4279 | 0 |
|
4280 | 0 | if (NS_FAILED(rv)) |
4281 | 0 | return rv; |
4282 | 0 | |
4283 | 0 | if (offsets.offset != offsets.secondaryOffset) |
4284 | 0 | fc->MaintainSelection(); |
4285 | 0 |
|
4286 | 0 | if (isEditor && !mouseEvent->IsShift() && |
4287 | 0 | (offsets.EndOffset() - offsets.StartOffset()) == 1) |
4288 | 0 | { |
4289 | 0 | // A single node is selected and we aren't extending an existing |
4290 | 0 | // selection, which means the user clicked directly on an object (either |
4291 | 0 | // -moz-user-select: all or a non-text node without children). |
4292 | 0 | // Therefore, disable selection extension during mouse moves. |
4293 | 0 | // XXX This is a bit hacky; shouldn't editor be able to deal with this? |
4294 | 0 | fc->SetDragState(false); |
4295 | 0 | } |
4296 | 0 |
|
4297 | 0 | return rv; |
4298 | 0 | } |
4299 | | |
4300 | | /* |
4301 | | * SelectByTypeAtPoint |
4302 | | * |
4303 | | * Search for selectable content at point and attempt to select |
4304 | | * based on the start and end selection behaviours. |
4305 | | * |
4306 | | * @param aPresContext Presentation context |
4307 | | * @param aPoint Point at which selection will occur. Coordinates |
4308 | | * should be relaitve to this frame. |
4309 | | * @param aBeginAmountType, aEndAmountType Selection behavior, see |
4310 | | * nsIFrame for definitions. |
4311 | | * @param aSelectFlags Selection flags defined in nsFame.h. |
4312 | | * @return success or failure at finding suitable content to select. |
4313 | | */ |
4314 | | nsresult |
4315 | | nsFrame::SelectByTypeAtPoint(nsPresContext* aPresContext, |
4316 | | const nsPoint& aPoint, |
4317 | | nsSelectionAmount aBeginAmountType, |
4318 | | nsSelectionAmount aEndAmountType, |
4319 | | uint32_t aSelectFlags) |
4320 | 0 | { |
4321 | 0 | NS_ENSURE_ARG_POINTER(aPresContext); |
4322 | 0 |
|
4323 | 0 | // No point in selecting if selection is turned off |
4324 | 0 | if (DisplaySelection(aPresContext) == nsISelectionController::SELECTION_OFF) |
4325 | 0 | return NS_OK; |
4326 | 0 | |
4327 | 0 | ContentOffsets offsets = GetContentOffsetsFromPoint(aPoint, SKIP_HIDDEN); |
4328 | 0 | if (!offsets.content) |
4329 | 0 | return NS_ERROR_FAILURE; |
4330 | 0 | |
4331 | 0 | int32_t offset; |
4332 | 0 | const nsFrameSelection* frameSelection = |
4333 | 0 | PresContext()->GetPresShell()->ConstFrameSelection(); |
4334 | 0 | nsIFrame* theFrame = frameSelection-> |
4335 | 0 | GetFrameForNodeOffset(offsets.content, offsets.offset, |
4336 | 0 | offsets.associate, &offset); |
4337 | 0 | if (!theFrame) |
4338 | 0 | return NS_ERROR_FAILURE; |
4339 | 0 | |
4340 | 0 | nsFrame* frame = static_cast<nsFrame*>(theFrame); |
4341 | 0 | return frame->PeekBackwardAndForward(aBeginAmountType, aEndAmountType, offset, |
4342 | 0 | aBeginAmountType != eSelectWord, |
4343 | 0 | aSelectFlags); |
4344 | 0 | } |
4345 | | |
4346 | | /** |
4347 | | * Multiple Mouse Press -- line or paragraph selection -- for the frame. |
4348 | | * Wouldn't it be nice if this didn't have to be hardwired into Frame code? |
4349 | | */ |
4350 | | NS_IMETHODIMP |
4351 | | nsFrame::HandleMultiplePress(nsPresContext* aPresContext, |
4352 | | WidgetGUIEvent* aEvent, |
4353 | | nsEventStatus* aEventStatus, |
4354 | | bool aControlHeld) |
4355 | 0 | { |
4356 | 0 | NS_ENSURE_ARG_POINTER(aEvent); |
4357 | 0 | NS_ENSURE_ARG_POINTER(aEventStatus); |
4358 | 0 |
|
4359 | 0 | if (nsEventStatus_eConsumeNoDefault == *aEventStatus || |
4360 | 0 | DisplaySelection(aPresContext) == nsISelectionController::SELECTION_OFF) { |
4361 | 0 | return NS_OK; |
4362 | 0 | } |
4363 | 0 | |
4364 | 0 | // Find out whether we're doing line or paragraph selection. |
4365 | 0 | // If browser.triple_click_selects_paragraph is true, triple-click selects paragraph. |
4366 | 0 | // Otherwise, triple-click selects line, and quadruple-click selects paragraph |
4367 | 0 | // (on platforms that support quadruple-click). |
4368 | 0 | nsSelectionAmount beginAmount, endAmount; |
4369 | 0 | WidgetMouseEvent* mouseEvent = aEvent->AsMouseEvent(); |
4370 | 0 | if (!mouseEvent) { |
4371 | 0 | return NS_OK; |
4372 | 0 | } |
4373 | 0 | |
4374 | 0 | if (mouseEvent->mClickCount == 4) { |
4375 | 0 | beginAmount = endAmount = eSelectParagraph; |
4376 | 0 | } else if (mouseEvent->mClickCount == 3) { |
4377 | 0 | if (Preferences::GetBool("browser.triple_click_selects_paragraph")) { |
4378 | 0 | beginAmount = endAmount = eSelectParagraph; |
4379 | 0 | } else { |
4380 | 0 | beginAmount = eSelectBeginLine; |
4381 | 0 | endAmount = eSelectEndLine; |
4382 | 0 | } |
4383 | 0 | } else if (mouseEvent->mClickCount == 2) { |
4384 | 0 | // We only want inline frames; PeekBackwardAndForward dislikes blocks |
4385 | 0 | beginAmount = endAmount = eSelectWord; |
4386 | 0 | } else { |
4387 | 0 | return NS_OK; |
4388 | 0 | } |
4389 | 0 | |
4390 | 0 | nsPoint relPoint = |
4391 | 0 | nsLayoutUtils::GetEventCoordinatesRelativeTo(mouseEvent, this); |
4392 | 0 | return SelectByTypeAtPoint(aPresContext, relPoint, beginAmount, endAmount, |
4393 | 0 | (aControlHeld ? SELECT_ACCUMULATE : 0)); |
4394 | 0 | } |
4395 | | |
4396 | | nsresult |
4397 | | nsFrame::PeekBackwardAndForward(nsSelectionAmount aAmountBack, |
4398 | | nsSelectionAmount aAmountForward, |
4399 | | int32_t aStartPos, |
4400 | | bool aJumpLines, |
4401 | | uint32_t aSelectFlags) |
4402 | 0 | { |
4403 | 0 | nsIFrame* baseFrame = this; |
4404 | 0 | int32_t baseOffset = aStartPos; |
4405 | 0 | nsresult rv; |
4406 | 0 |
|
4407 | 0 | if (aAmountBack == eSelectWord) { |
4408 | 0 | // To avoid selecting the previous word when at start of word, |
4409 | 0 | // first move one character forward. |
4410 | 0 | nsPeekOffsetStruct pos(eSelectCharacter, |
4411 | 0 | eDirNext, |
4412 | 0 | aStartPos, |
4413 | 0 | nsPoint(0, 0), |
4414 | 0 | aJumpLines, |
4415 | 0 | true, //limit on scrolled views |
4416 | 0 | false, |
4417 | 0 | false, |
4418 | 0 | false); |
4419 | 0 | rv = PeekOffset(&pos); |
4420 | 0 | if (NS_SUCCEEDED(rv)) { |
4421 | 0 | baseFrame = pos.mResultFrame; |
4422 | 0 | baseOffset = pos.mContentOffset; |
4423 | 0 | } |
4424 | 0 | } |
4425 | 0 |
|
4426 | 0 | // Use peek offset one way then the other: |
4427 | 0 | nsPeekOffsetStruct startpos(aAmountBack, |
4428 | 0 | eDirPrevious, |
4429 | 0 | baseOffset, |
4430 | 0 | nsPoint(0, 0), |
4431 | 0 | aJumpLines, |
4432 | 0 | true, //limit on scrolled views |
4433 | 0 | false, |
4434 | 0 | false, |
4435 | 0 | false); |
4436 | 0 | rv = baseFrame->PeekOffset(&startpos); |
4437 | 0 | if (NS_FAILED(rv)) |
4438 | 0 | return rv; |
4439 | 0 | |
4440 | 0 | nsPeekOffsetStruct endpos(aAmountForward, |
4441 | 0 | eDirNext, |
4442 | 0 | aStartPos, |
4443 | 0 | nsPoint(0, 0), |
4444 | 0 | aJumpLines, |
4445 | 0 | true, //limit on scrolled views |
4446 | 0 | false, |
4447 | 0 | false, |
4448 | 0 | false); |
4449 | 0 | rv = PeekOffset(&endpos); |
4450 | 0 | if (NS_FAILED(rv)) |
4451 | 0 | return rv; |
4452 | 0 | |
4453 | 0 | // Keep frameSelection alive. |
4454 | 0 | RefPtr<nsFrameSelection> frameSelection = GetFrameSelection(); |
4455 | 0 |
|
4456 | 0 | rv = frameSelection->HandleClick(startpos.mResultContent, |
4457 | 0 | startpos.mContentOffset, startpos.mContentOffset, |
4458 | 0 | false, (aSelectFlags & SELECT_ACCUMULATE), |
4459 | 0 | CARET_ASSOCIATE_AFTER); |
4460 | 0 | if (NS_FAILED(rv)) |
4461 | 0 | return rv; |
4462 | 0 | |
4463 | 0 | rv = frameSelection->HandleClick(endpos.mResultContent, |
4464 | 0 | endpos.mContentOffset, endpos.mContentOffset, |
4465 | 0 | true, false, |
4466 | 0 | CARET_ASSOCIATE_BEFORE); |
4467 | 0 | if (NS_FAILED(rv)) |
4468 | 0 | return rv; |
4469 | 0 | |
4470 | 0 | // maintain selection |
4471 | 0 | return frameSelection->MaintainSelection(aAmountBack); |
4472 | 0 | } |
4473 | | |
4474 | | NS_IMETHODIMP nsFrame::HandleDrag(nsPresContext* aPresContext, |
4475 | | WidgetGUIEvent* aEvent, |
4476 | | nsEventStatus* aEventStatus) |
4477 | 0 | { |
4478 | 0 | MOZ_ASSERT(aEvent->mClass == eMouseEventClass, |
4479 | 0 | "HandleDrag can only handle mouse event"); |
4480 | 0 |
|
4481 | 0 | RefPtr<nsFrameSelection> frameselection = GetFrameSelection(); |
4482 | 0 | bool mouseDown = frameselection->GetDragState(); |
4483 | 0 | if (!mouseDown) { |
4484 | 0 | return NS_OK; |
4485 | 0 | } |
4486 | 0 | |
4487 | 0 | nsIFrame* scrollbar = |
4488 | 0 | nsLayoutUtils::GetClosestFrameOfType(this, LayoutFrameType::Scrollbar); |
4489 | 0 | if (!scrollbar) { |
4490 | 0 | // XXX Do we really need to exclude non-selectable content here? |
4491 | 0 | // GetContentOffsetsFromPoint can handle it just fine, although some |
4492 | 0 | // other stuff might not like it. |
4493 | 0 | // NOTE: DisplaySelection() returns SELECTION_OFF for non-selectable frames. |
4494 | 0 | if (DisplaySelection(aPresContext) == nsISelectionController::SELECTION_OFF) { |
4495 | 0 | return NS_OK; |
4496 | 0 | } |
4497 | 0 | } |
4498 | 0 | |
4499 | 0 | frameselection->StopAutoScrollTimer(); |
4500 | 0 |
|
4501 | 0 | // Check if we are dragging in a table cell |
4502 | 0 | nsCOMPtr<nsIContent> parentContent; |
4503 | 0 | int32_t contentOffset; |
4504 | 0 | TableSelection target; |
4505 | 0 | WidgetMouseEvent* mouseEvent = aEvent->AsMouseEvent(); |
4506 | 0 | nsCOMPtr<nsIPresShell> presShell = aPresContext->PresShell(); |
4507 | 0 | nsresult result; |
4508 | 0 | result = GetDataForTableSelection(frameselection, presShell, mouseEvent, |
4509 | 0 | getter_AddRefs(parentContent), |
4510 | 0 | &contentOffset, &target); |
4511 | 0 |
|
4512 | 0 | AutoWeakFrame weakThis = this; |
4513 | 0 | if (NS_SUCCEEDED(result) && parentContent) { |
4514 | 0 | frameselection->HandleTableSelection(parentContent, contentOffset, target, |
4515 | 0 | mouseEvent); |
4516 | 0 | } else { |
4517 | 0 | nsPoint pt = nsLayoutUtils::GetEventCoordinatesRelativeTo(mouseEvent, this); |
4518 | 0 | frameselection->HandleDrag(this, pt); |
4519 | 0 | } |
4520 | 0 |
|
4521 | 0 | // The frameselection object notifies selection listeners synchronously above |
4522 | 0 | // which might have killed us. |
4523 | 0 | if (!weakThis.IsAlive()) { |
4524 | 0 | return NS_OK; |
4525 | 0 | } |
4526 | 0 | |
4527 | 0 | // get the nearest scrollframe |
4528 | 0 | nsIScrollableFrame* scrollFrame = |
4529 | 0 | nsLayoutUtils::GetNearestScrollableFrame(this, |
4530 | 0 | nsLayoutUtils::SCROLLABLE_SAME_DOC | |
4531 | 0 | nsLayoutUtils::SCROLLABLE_INCLUDE_HIDDEN); |
4532 | 0 |
|
4533 | 0 | if (scrollFrame) { |
4534 | 0 | nsIFrame* capturingFrame = scrollFrame->GetScrolledFrame(); |
4535 | 0 | if (capturingFrame) { |
4536 | 0 | nsPoint pt = nsLayoutUtils::GetEventCoordinatesRelativeTo(mouseEvent, |
4537 | 0 | capturingFrame); |
4538 | 0 | frameselection->StartAutoScrollTimer(capturingFrame, pt, 30); |
4539 | 0 | } |
4540 | 0 | } |
4541 | 0 |
|
4542 | 0 | return NS_OK; |
4543 | 0 | } |
4544 | | |
4545 | | /** |
4546 | | * This static method handles part of the nsFrame::HandleRelease in a way |
4547 | | * which doesn't rely on the nsFrame object to stay alive. |
4548 | | */ |
4549 | | static nsresult |
4550 | | HandleFrameSelection(nsFrameSelection* aFrameSelection, |
4551 | | nsIFrame::ContentOffsets& aOffsets, |
4552 | | bool aHandleTableSel, |
4553 | | int32_t aContentOffsetForTableSel, |
4554 | | TableSelection aTargetForTableSel, |
4555 | | nsIContent* aParentContentForTableSel, |
4556 | | WidgetGUIEvent* aEvent, |
4557 | | nsEventStatus* aEventStatus) |
4558 | 0 | { |
4559 | 0 | if (!aFrameSelection) { |
4560 | 0 | return NS_OK; |
4561 | 0 | } |
4562 | 0 | |
4563 | 0 | nsresult rv = NS_OK; |
4564 | 0 |
|
4565 | 0 | if (nsEventStatus_eConsumeNoDefault != *aEventStatus) { |
4566 | 0 | if (!aHandleTableSel) { |
4567 | 0 | if (!aOffsets.content || !aFrameSelection->HasDelayedCaretData()) { |
4568 | 0 | return NS_ERROR_FAILURE; |
4569 | 0 | } |
4570 | 0 | |
4571 | 0 | // We are doing this to simulate what we would have done on HandlePress. |
4572 | 0 | // We didn't do it there to give the user an opportunity to drag |
4573 | 0 | // the text, but since they didn't drag, we want to place the |
4574 | 0 | // caret. |
4575 | 0 | // However, we'll use the mouse position from the release, since: |
4576 | 0 | // * it's easier |
4577 | 0 | // * that's the normal click position to use (although really, in |
4578 | 0 | // the normal case, small movements that don't count as a drag |
4579 | 0 | // can do selection) |
4580 | 0 | aFrameSelection->SetDragState(true); |
4581 | 0 |
|
4582 | 0 | rv = aFrameSelection->HandleClick(aOffsets.content, |
4583 | 0 | aOffsets.StartOffset(), |
4584 | 0 | aOffsets.EndOffset(), |
4585 | 0 | aFrameSelection->IsShiftDownInDelayedCaretData(), |
4586 | 0 | false, |
4587 | 0 | aOffsets.associate); |
4588 | 0 | if (NS_FAILED(rv)) { |
4589 | 0 | return rv; |
4590 | 0 | } |
4591 | 0 | } else if (aParentContentForTableSel) { |
4592 | 0 | aFrameSelection->SetDragState(false); |
4593 | 0 | rv = aFrameSelection->HandleTableSelection( |
4594 | 0 | aParentContentForTableSel, |
4595 | 0 | aContentOffsetForTableSel, |
4596 | 0 | aTargetForTableSel, |
4597 | 0 | aEvent->AsMouseEvent()); |
4598 | 0 | if (NS_FAILED(rv)) { |
4599 | 0 | return rv; |
4600 | 0 | } |
4601 | 0 | } |
4602 | 0 | aFrameSelection->SetDelayedCaretData(0); |
4603 | 0 | } |
4604 | 0 |
|
4605 | 0 | aFrameSelection->SetDragState(false); |
4606 | 0 | aFrameSelection->StopAutoScrollTimer(); |
4607 | 0 |
|
4608 | 0 | return NS_OK; |
4609 | 0 | } |
4610 | | |
4611 | | NS_IMETHODIMP nsFrame::HandleRelease(nsPresContext* aPresContext, |
4612 | | WidgetGUIEvent* aEvent, |
4613 | | nsEventStatus* aEventStatus) |
4614 | 0 | { |
4615 | 0 | if (aEvent->mClass != eMouseEventClass) { |
4616 | 0 | return NS_OK; |
4617 | 0 | } |
4618 | 0 | |
4619 | 0 | nsIFrame* activeFrame = GetActiveSelectionFrame(aPresContext, this); |
4620 | 0 |
|
4621 | 0 | nsCOMPtr<nsIContent> captureContent = nsIPresShell::GetCapturingContent(); |
4622 | 0 |
|
4623 | 0 | // We can unconditionally stop capturing because |
4624 | 0 | // we should never be capturing when the mouse button is up |
4625 | 0 | nsIPresShell::SetCapturingContent(nullptr, 0); |
4626 | 0 |
|
4627 | 0 | bool selectionOff = |
4628 | 0 | (DisplaySelection(aPresContext) == nsISelectionController::SELECTION_OFF); |
4629 | 0 |
|
4630 | 0 | RefPtr<nsFrameSelection> frameselection; |
4631 | 0 | ContentOffsets offsets; |
4632 | 0 | nsCOMPtr<nsIContent> parentContent; |
4633 | 0 | int32_t contentOffsetForTableSel = 0; |
4634 | 0 | TableSelection targetForTableSel = TableSelection::None; |
4635 | 0 | bool handleTableSelection = true; |
4636 | 0 |
|
4637 | 0 | if (!selectionOff) { |
4638 | 0 | frameselection = GetFrameSelection(); |
4639 | 0 | if (nsEventStatus_eConsumeNoDefault != *aEventStatus && frameselection) { |
4640 | 0 | // Check if the frameselection recorded the mouse going down. |
4641 | 0 | // If not, the user must have clicked in a part of the selection. |
4642 | 0 | // Place the caret before continuing! |
4643 | 0 |
|
4644 | 0 | if (frameselection->MouseDownRecorded()) { |
4645 | 0 | nsPoint pt = nsLayoutUtils::GetEventCoordinatesRelativeTo(aEvent, this); |
4646 | 0 | offsets = GetContentOffsetsFromPoint(pt, SKIP_HIDDEN); |
4647 | 0 | handleTableSelection = false; |
4648 | 0 | } else { |
4649 | 0 | GetDataForTableSelection(frameselection, PresShell(), |
4650 | 0 | aEvent->AsMouseEvent(), |
4651 | 0 | getter_AddRefs(parentContent), |
4652 | 0 | &contentOffsetForTableSel, |
4653 | 0 | &targetForTableSel); |
4654 | 0 | } |
4655 | 0 | } |
4656 | 0 | } |
4657 | 0 |
|
4658 | 0 | // We might be capturing in some other document and the event just happened to |
4659 | 0 | // trickle down here. Make sure that document's frame selection is notified. |
4660 | 0 | // Note, this may cause the current nsFrame object to be deleted, bug 336592. |
4661 | 0 | RefPtr<nsFrameSelection> frameSelection; |
4662 | 0 | if (activeFrame != this && |
4663 | 0 | static_cast<nsFrame*>(activeFrame)->DisplaySelection(activeFrame->PresContext()) |
4664 | 0 | != nsISelectionController::SELECTION_OFF) { |
4665 | 0 | frameSelection = activeFrame->GetFrameSelection(); |
4666 | 0 | } |
4667 | 0 |
|
4668 | 0 | // Also check the selection of the capturing content which might be in a |
4669 | 0 | // different document. |
4670 | 0 | if (!frameSelection && captureContent) { |
4671 | 0 | nsIDocument* doc = captureContent->GetUncomposedDoc(); |
4672 | 0 | if (doc) { |
4673 | 0 | nsIPresShell* capturingShell = doc->GetShell(); |
4674 | 0 | if (capturingShell && capturingShell != PresContext()->GetPresShell()) { |
4675 | 0 | frameSelection = capturingShell->FrameSelection(); |
4676 | 0 | } |
4677 | 0 | } |
4678 | 0 | } |
4679 | 0 |
|
4680 | 0 | if (frameSelection) { |
4681 | 0 | frameSelection->SetDragState(false); |
4682 | 0 | frameSelection->StopAutoScrollTimer(); |
4683 | 0 | nsIScrollableFrame* scrollFrame = |
4684 | 0 | nsLayoutUtils::GetNearestScrollableFrame(this, |
4685 | 0 | nsLayoutUtils::SCROLLABLE_SAME_DOC | |
4686 | 0 | nsLayoutUtils::SCROLLABLE_INCLUDE_HIDDEN); |
4687 | 0 | if (scrollFrame) { |
4688 | 0 | // Perform any additional scrolling needed to maintain CSS snap point |
4689 | 0 | // requirements when autoscrolling is over. |
4690 | 0 | scrollFrame->ScrollSnap(); |
4691 | 0 | } |
4692 | 0 | } |
4693 | 0 |
|
4694 | 0 | // Do not call any methods of the current object after this point!!! |
4695 | 0 | // The object is perhaps dead! |
4696 | 0 |
|
4697 | 0 | return selectionOff |
4698 | 0 | ? NS_OK |
4699 | 0 | : HandleFrameSelection(frameselection, offsets, handleTableSelection, |
4700 | 0 | contentOffsetForTableSel, targetForTableSel, |
4701 | 0 | parentContent, aEvent, aEventStatus); |
4702 | 0 | } |
4703 | | |
4704 | | struct MOZ_STACK_CLASS FrameContentRange { |
4705 | | FrameContentRange(nsIContent* aContent, int32_t aStart, int32_t aEnd) : |
4706 | 0 | content(aContent), start(aStart), end(aEnd) { } |
4707 | | nsCOMPtr<nsIContent> content; |
4708 | | int32_t start; |
4709 | | int32_t end; |
4710 | | }; |
4711 | | |
4712 | | // Retrieve the content offsets of a frame |
4713 | 0 | static FrameContentRange GetRangeForFrame(nsIFrame* aFrame) { |
4714 | 0 | nsIContent* content = aFrame->GetContent(); |
4715 | 0 | if (!content) { |
4716 | 0 | NS_WARNING("Frame has no content"); |
4717 | 0 | return FrameContentRange(nullptr, -1, -1); |
4718 | 0 | } |
4719 | 0 |
|
4720 | 0 | LayoutFrameType type = aFrame->Type(); |
4721 | 0 | if (type == LayoutFrameType::Text) { |
4722 | 0 | int32_t offset, offsetEnd; |
4723 | 0 | aFrame->GetOffsets(offset, offsetEnd); |
4724 | 0 | return FrameContentRange(content, offset, offsetEnd); |
4725 | 0 | } |
4726 | 0 | |
4727 | 0 | if (type == LayoutFrameType::Br) { |
4728 | 0 | nsIContent* parent = content->GetParent(); |
4729 | 0 | int32_t beginOffset = parent->ComputeIndexOf(content); |
4730 | 0 | return FrameContentRange(parent, beginOffset, beginOffset); |
4731 | 0 | } |
4732 | 0 | |
4733 | 0 | while (content->IsRootOfAnonymousSubtree()) { |
4734 | 0 | content = content->GetParent(); |
4735 | 0 | } |
4736 | 0 |
|
4737 | 0 | nsIContent* parent = content->GetParent(); |
4738 | 0 | if (nsLayoutUtils::GetAsBlock(aFrame) || !parent) { |
4739 | 0 | return FrameContentRange(content, 0, content->GetChildCount()); |
4740 | 0 | } |
4741 | 0 | |
4742 | 0 | // TODO(emilio): Revise this in presence of Shadow DOM / display: contents, |
4743 | 0 | // it's likely that we don't want to just walk the light tree, and we need to |
4744 | 0 | // change the representation of FrameContentRange. |
4745 | 0 | int32_t index = parent->ComputeIndexOf(content); |
4746 | 0 | MOZ_ASSERT(index >= 0); |
4747 | 0 | return FrameContentRange(parent, index, index + 1); |
4748 | 0 | } |
4749 | | |
4750 | | // The FrameTarget represents the closest frame to a point that can be selected |
4751 | | // The frame is the frame represented, frameEdge says whether one end of the |
4752 | | // frame is the result (in which case different handling is needed), and |
4753 | | // afterFrame says which end is repersented if frameEdge is true |
4754 | | struct FrameTarget { |
4755 | | FrameTarget(nsIFrame* aFrame, bool aFrameEdge, bool aAfterFrame) |
4756 | | : frame(aFrame) |
4757 | | , frameEdge(aFrameEdge) |
4758 | | , afterFrame(aAfterFrame) |
4759 | 0 | {} |
4760 | | |
4761 | 0 | static FrameTarget Null() { |
4762 | 0 | return FrameTarget(nullptr, false, false); |
4763 | 0 | } |
4764 | | |
4765 | 0 | bool IsNull() { |
4766 | 0 | return !frame; |
4767 | 0 | } |
4768 | | nsIFrame* frame; |
4769 | | bool frameEdge; |
4770 | | bool afterFrame; |
4771 | | }; |
4772 | | |
4773 | | // See function implementation for information |
4774 | | static FrameTarget GetSelectionClosestFrame(nsIFrame* aFrame, |
4775 | | const nsPoint& aPoint, |
4776 | | uint32_t aFlags); |
4777 | | |
4778 | | static bool SelfIsSelectable(nsIFrame* aFrame, uint32_t aFlags) |
4779 | 0 | { |
4780 | 0 | if ((aFlags & nsIFrame::SKIP_HIDDEN) && |
4781 | 0 | !aFrame->StyleVisibility()->IsVisible()) { |
4782 | 0 | return false; |
4783 | 0 | } |
4784 | 0 | return !aFrame->IsGeneratedContentFrame() && |
4785 | 0 | aFrame->StyleUIReset()->mUserSelect != StyleUserSelect::None; |
4786 | 0 | } |
4787 | | |
4788 | 0 | static bool SelectionDescendToKids(nsIFrame* aFrame) { |
4789 | 0 | StyleUserSelect style = aFrame->StyleUIReset()->mUserSelect; |
4790 | 0 | nsIFrame* parent = aFrame->GetParent(); |
4791 | 0 | // If we are only near (not directly over) then don't traverse |
4792 | 0 | // frames with independent selection (e.g. text and list controls) |
4793 | 0 | // unless we're already inside such a frame (see bug 268497). Note that this |
4794 | 0 | // prevents any of the users of this method from entering form controls. |
4795 | 0 | // XXX We might want some way to allow using the up-arrow to go into a form |
4796 | 0 | // control, but the focus didn't work right anyway; it'd probably be enough |
4797 | 0 | // if the left and right arrows could enter textboxes (which I don't believe |
4798 | 0 | // they can at the moment) |
4799 | 0 | return !aFrame->IsGeneratedContentFrame() && |
4800 | 0 | style != StyleUserSelect::All && |
4801 | 0 | style != StyleUserSelect::None && |
4802 | 0 | ((parent->GetStateBits() & NS_FRAME_INDEPENDENT_SELECTION) || |
4803 | 0 | !(aFrame->GetStateBits() & NS_FRAME_INDEPENDENT_SELECTION)); |
4804 | 0 | } |
4805 | | |
4806 | | static FrameTarget GetSelectionClosestFrameForChild(nsIFrame* aChild, |
4807 | | const nsPoint& aPoint, |
4808 | | uint32_t aFlags) |
4809 | 0 | { |
4810 | 0 | nsIFrame* parent = aChild->GetParent(); |
4811 | 0 | if (SelectionDescendToKids(aChild)) { |
4812 | 0 | nsPoint pt = aPoint - aChild->GetOffsetTo(parent); |
4813 | 0 | return GetSelectionClosestFrame(aChild, pt, aFlags); |
4814 | 0 | } |
4815 | 0 | return FrameTarget(aChild, false, false); |
4816 | 0 | } |
4817 | | |
4818 | | // When the cursor needs to be at the beginning of a block, it shouldn't be |
4819 | | // before the first child. A click on a block whose first child is a block |
4820 | | // should put the cursor in the child. The cursor shouldn't be between the |
4821 | | // blocks, because that's not where it's expected. |
4822 | | // Note that this method is guaranteed to succeed. |
4823 | | static FrameTarget DrillDownToSelectionFrame(nsIFrame* aFrame, |
4824 | 0 | bool aEndFrame, uint32_t aFlags) { |
4825 | 0 | if (SelectionDescendToKids(aFrame)) { |
4826 | 0 | nsIFrame* result = nullptr; |
4827 | 0 | nsIFrame *frame = aFrame->PrincipalChildList().FirstChild(); |
4828 | 0 | if (!aEndFrame) { |
4829 | 0 | while (frame && (!SelfIsSelectable(frame, aFlags) || |
4830 | 0 | frame->IsEmpty())) |
4831 | 0 | frame = frame->GetNextSibling(); |
4832 | 0 | if (frame) |
4833 | 0 | result = frame; |
4834 | 0 | } else { |
4835 | 0 | // Because the frame tree is singly linked, to find the last frame, |
4836 | 0 | // we have to iterate through all the frames |
4837 | 0 | // XXX I have a feeling this could be slow for long blocks, although |
4838 | 0 | // I can't find any slowdowns |
4839 | 0 | while (frame) { |
4840 | 0 | if (!frame->IsEmpty() && SelfIsSelectable(frame, aFlags)) |
4841 | 0 | result = frame; |
4842 | 0 | frame = frame->GetNextSibling(); |
4843 | 0 | } |
4844 | 0 | } |
4845 | 0 | if (result) |
4846 | 0 | return DrillDownToSelectionFrame(result, aEndFrame, aFlags); |
4847 | 0 | } |
4848 | 0 | // If the current frame has no targetable children, target the current frame |
4849 | 0 | return FrameTarget(aFrame, true, aEndFrame); |
4850 | 0 | } |
4851 | | |
4852 | | // This method finds the closest valid FrameTarget on a given line; if there is |
4853 | | // no valid FrameTarget on the line, it returns a null FrameTarget |
4854 | | static FrameTarget GetSelectionClosestFrameForLine( |
4855 | | nsBlockFrame* aParent, |
4856 | | nsBlockFrame::LineIterator aLine, |
4857 | | const nsPoint& aPoint, |
4858 | | uint32_t aFlags) |
4859 | 0 | { |
4860 | 0 | // Account for end of lines (any iterator from the block is valid) |
4861 | 0 | if (aLine == aParent->LinesEnd()) |
4862 | 0 | return DrillDownToSelectionFrame(aParent, true, aFlags); |
4863 | 0 | nsIFrame* frame = aLine->mFirstChild; |
4864 | 0 | nsIFrame* closestFromIStart = nullptr; |
4865 | 0 | nsIFrame* closestFromIEnd = nullptr; |
4866 | 0 | nscoord closestIStart = aLine->IStart(), closestIEnd = aLine->IEnd(); |
4867 | 0 | WritingMode wm = aLine->mWritingMode; |
4868 | 0 | LogicalPoint pt(wm, aPoint, aLine->mContainerSize); |
4869 | 0 | bool canSkipBr = false; |
4870 | 0 | for (int32_t n = aLine->GetChildCount(); n; |
4871 | 0 | --n, frame = frame->GetNextSibling()) { |
4872 | 0 | // Skip brFrames. Can only skip if the line contains at least |
4873 | 0 | // one selectable and non-empty frame before |
4874 | 0 | if (!SelfIsSelectable(frame, aFlags) || frame->IsEmpty() || |
4875 | 0 | (canSkipBr && frame->IsBrFrame())) { |
4876 | 0 | continue; |
4877 | 0 | } |
4878 | 0 | canSkipBr = true; |
4879 | 0 | LogicalRect frameRect = LogicalRect(wm, frame->GetRect(), |
4880 | 0 | aLine->mContainerSize); |
4881 | 0 | if (pt.I(wm) >= frameRect.IStart(wm)) { |
4882 | 0 | if (pt.I(wm) < frameRect.IEnd(wm)) { |
4883 | 0 | return GetSelectionClosestFrameForChild(frame, aPoint, aFlags); |
4884 | 0 | } |
4885 | 0 | if (frameRect.IEnd(wm) >= closestIStart) { |
4886 | 0 | closestFromIStart = frame; |
4887 | 0 | closestIStart = frameRect.IEnd(wm); |
4888 | 0 | } |
4889 | 0 | } else { |
4890 | 0 | if (frameRect.IStart(wm) <= closestIEnd) { |
4891 | 0 | closestFromIEnd = frame; |
4892 | 0 | closestIEnd = frameRect.IStart(wm); |
4893 | 0 | } |
4894 | 0 | } |
4895 | 0 | } |
4896 | 0 | if (!closestFromIStart && !closestFromIEnd) { |
4897 | 0 | // We should only get here if there are no selectable frames on a line |
4898 | 0 | // XXX Do we need more elaborate handling here? |
4899 | 0 | return FrameTarget::Null(); |
4900 | 0 | } |
4901 | 0 | if (closestFromIStart && |
4902 | 0 | (!closestFromIEnd || |
4903 | 0 | (abs(pt.I(wm) - closestIStart) <= abs(pt.I(wm) - closestIEnd)))) { |
4904 | 0 | return GetSelectionClosestFrameForChild(closestFromIStart, aPoint, |
4905 | 0 | aFlags); |
4906 | 0 | } |
4907 | 0 | return GetSelectionClosestFrameForChild(closestFromIEnd, aPoint, aFlags); |
4908 | 0 | } |
4909 | | |
4910 | | // This method is for the special handling we do for block frames; they're |
4911 | | // special because they represent paragraphs and because they are organized |
4912 | | // into lines, which have bounds that are not stored elsewhere in the |
4913 | | // frame tree. Returns a null FrameTarget for frames which are not |
4914 | | // blocks or blocks with no lines except editable one. |
4915 | | static FrameTarget GetSelectionClosestFrameForBlock(nsIFrame* aFrame, |
4916 | | const nsPoint& aPoint, |
4917 | | uint32_t aFlags) |
4918 | 0 | { |
4919 | 0 | nsBlockFrame* bf = nsLayoutUtils::GetAsBlock(aFrame); // used only for QI |
4920 | 0 | if (!bf) |
4921 | 0 | return FrameTarget::Null(); |
4922 | 0 | |
4923 | 0 | // This code searches for the correct line |
4924 | 0 | nsBlockFrame::LineIterator end = bf->LinesEnd(); |
4925 | 0 | nsBlockFrame::LineIterator curLine = bf->LinesBegin(); |
4926 | 0 | nsBlockFrame::LineIterator closestLine = end; |
4927 | 0 |
|
4928 | 0 | if (curLine != end) { |
4929 | 0 | // Convert aPoint into a LogicalPoint in the writing-mode of this block |
4930 | 0 | WritingMode wm = curLine->mWritingMode; |
4931 | 0 | LogicalPoint pt(wm, aPoint, curLine->mContainerSize); |
4932 | 0 | do { |
4933 | 0 | // Check to see if our point lies within the line's block-direction bounds |
4934 | 0 | nscoord BCoord = pt.B(wm) - curLine->BStart(); |
4935 | 0 | nscoord BSize = curLine->BSize(); |
4936 | 0 | if (BCoord >= 0 && BCoord < BSize) { |
4937 | 0 | closestLine = curLine; |
4938 | 0 | break; // We found the line; stop looking |
4939 | 0 | } |
4940 | 0 | if (BCoord < 0) |
4941 | 0 | break; |
4942 | 0 | ++curLine; |
4943 | 0 | } while (curLine != end); |
4944 | 0 |
|
4945 | 0 | if (closestLine == end) { |
4946 | 0 | nsBlockFrame::LineIterator prevLine = curLine.prev(); |
4947 | 0 | nsBlockFrame::LineIterator nextLine = curLine; |
4948 | 0 | // Avoid empty lines |
4949 | 0 | while (nextLine != end && nextLine->IsEmpty()) |
4950 | 0 | ++nextLine; |
4951 | 0 | while (prevLine != end && prevLine->IsEmpty()) |
4952 | 0 | --prevLine; |
4953 | 0 |
|
4954 | 0 | // This hidden pref dictates whether a point above or below all lines comes |
4955 | 0 | // up with a line or the beginning or end of the frame; 0 on Windows, |
4956 | 0 | // 1 on other platforms by default at the writing of this code |
4957 | 0 | int32_t dragOutOfFrame = |
4958 | 0 | Preferences::GetInt("browser.drag_out_of_frame_style"); |
4959 | 0 |
|
4960 | 0 | if (prevLine == end) { |
4961 | 0 | if (dragOutOfFrame == 1 || nextLine == end) |
4962 | 0 | return DrillDownToSelectionFrame(aFrame, false, aFlags); |
4963 | 0 | closestLine = nextLine; |
4964 | 0 | } else if (nextLine == end) { |
4965 | 0 | if (dragOutOfFrame == 1) |
4966 | 0 | return DrillDownToSelectionFrame(aFrame, true, aFlags); |
4967 | 0 | closestLine = prevLine; |
4968 | 0 | } else { // Figure out which line is closer |
4969 | 0 | if (pt.B(wm) - prevLine->BEnd() < nextLine->BStart() - pt.B(wm)) |
4970 | 0 | closestLine = prevLine; |
4971 | 0 | else |
4972 | 0 | closestLine = nextLine; |
4973 | 0 | } |
4974 | 0 | } |
4975 | 0 | } |
4976 | 0 |
|
4977 | 0 | do { |
4978 | 0 | FrameTarget target = GetSelectionClosestFrameForLine(bf, closestLine, |
4979 | 0 | aPoint, aFlags); |
4980 | 0 | if (!target.IsNull()) |
4981 | 0 | return target; |
4982 | 0 | ++closestLine; |
4983 | 0 | } while (closestLine != end); |
4984 | 0 |
|
4985 | 0 | // Fall back to just targeting the last targetable place |
4986 | 0 | return DrillDownToSelectionFrame(aFrame, true, aFlags); |
4987 | 0 | } |
4988 | | |
4989 | | // GetSelectionClosestFrame is the helper function that calculates the closest |
4990 | | // frame to the given point. |
4991 | | // It doesn't completely account for offset styles, so needs to be used in |
4992 | | // restricted environments. |
4993 | | // Cannot handle overlapping frames correctly, so it should receive the output |
4994 | | // of GetFrameForPoint |
4995 | | // Guaranteed to return a valid FrameTarget |
4996 | | static FrameTarget GetSelectionClosestFrame(nsIFrame* aFrame, |
4997 | | const nsPoint& aPoint, |
4998 | | uint32_t aFlags) |
4999 | 0 | { |
5000 | 0 | { |
5001 | 0 | // Handle blocks; if the frame isn't a block, the method fails |
5002 | 0 | FrameTarget target = GetSelectionClosestFrameForBlock(aFrame, aPoint, aFlags); |
5003 | 0 | if (!target.IsNull()) |
5004 | 0 | return target; |
5005 | 0 | } |
5006 | 0 | |
5007 | 0 | nsIFrame *kid = aFrame->PrincipalChildList().FirstChild(); |
5008 | 0 |
|
5009 | 0 | if (kid) { |
5010 | 0 | // Go through all the child frames to find the closest one |
5011 | 0 | nsIFrame::FrameWithDistance closest = { nullptr, nscoord_MAX, nscoord_MAX }; |
5012 | 0 | for (; kid; kid = kid->GetNextSibling()) { |
5013 | 0 | if (!SelfIsSelectable(kid, aFlags) || kid->IsEmpty()) |
5014 | 0 | continue; |
5015 | 0 | |
5016 | 0 | kid->FindCloserFrameForSelection(aPoint, &closest); |
5017 | 0 | } |
5018 | 0 | if (closest.mFrame) { |
5019 | 0 | if (nsSVGUtils::IsInSVGTextSubtree(closest.mFrame)) |
5020 | 0 | return FrameTarget(closest.mFrame, false, false); |
5021 | 0 | return GetSelectionClosestFrameForChild(closest.mFrame, aPoint, aFlags); |
5022 | 0 | } |
5023 | 0 | } |
5024 | 0 | return FrameTarget(aFrame, false, false); |
5025 | 0 | } |
5026 | | |
5027 | | static nsIFrame::ContentOffsets |
5028 | | OffsetsForSingleFrame(nsIFrame* aFrame, const nsPoint& aPoint) |
5029 | 0 | { |
5030 | 0 | nsIFrame::ContentOffsets offsets; |
5031 | 0 | FrameContentRange range = GetRangeForFrame(aFrame); |
5032 | 0 | offsets.content = range.content; |
5033 | 0 | // If there are continuations (meaning it's not one rectangle), this is the |
5034 | 0 | // best this function can do |
5035 | 0 | if (aFrame->GetNextContinuation() || aFrame->GetPrevContinuation()) { |
5036 | 0 | offsets.offset = range.start; |
5037 | 0 | offsets.secondaryOffset = range.end; |
5038 | 0 | offsets.associate = CARET_ASSOCIATE_AFTER; |
5039 | 0 | return offsets; |
5040 | 0 | } |
5041 | 0 | |
5042 | 0 | // Figure out whether the offsets should be over, after, or before the frame |
5043 | 0 | nsRect rect(nsPoint(0, 0), aFrame->GetSize()); |
5044 | 0 |
|
5045 | 0 | bool isBlock = aFrame->GetDisplay() != StyleDisplay::Inline; |
5046 | 0 | bool isRtl = (aFrame->StyleVisibility()->mDirection == NS_STYLE_DIRECTION_RTL); |
5047 | 0 | if ((isBlock && rect.y < aPoint.y) || |
5048 | 0 | (!isBlock && ((isRtl && rect.x + rect.width / 2 > aPoint.x) || |
5049 | 0 | (!isRtl && rect.x + rect.width / 2 < aPoint.x)))) { |
5050 | 0 | offsets.offset = range.end; |
5051 | 0 | if (rect.Contains(aPoint)) |
5052 | 0 | offsets.secondaryOffset = range.start; |
5053 | 0 | else |
5054 | 0 | offsets.secondaryOffset = range.end; |
5055 | 0 | } else { |
5056 | 0 | offsets.offset = range.start; |
5057 | 0 | if (rect.Contains(aPoint)) |
5058 | 0 | offsets.secondaryOffset = range.end; |
5059 | 0 | else |
5060 | 0 | offsets.secondaryOffset = range.start; |
5061 | 0 | } |
5062 | 0 | offsets.associate = |
5063 | 0 | offsets.offset == range.start ? CARET_ASSOCIATE_AFTER : CARET_ASSOCIATE_BEFORE; |
5064 | 0 | return offsets; |
5065 | 0 | } |
5066 | | |
5067 | 0 | static nsIFrame* AdjustFrameForSelectionStyles(nsIFrame* aFrame) { |
5068 | 0 | nsIFrame* adjustedFrame = aFrame; |
5069 | 0 | for (nsIFrame* frame = aFrame; frame; frame = frame->GetParent()) |
5070 | 0 | { |
5071 | 0 | // These are the conditions that make all children not able to handle |
5072 | 0 | // a cursor. |
5073 | 0 | StyleUserSelect userSelect = frame->StyleUIReset()->mUserSelect; |
5074 | 0 | if (userSelect == StyleUserSelect::MozText) { |
5075 | 0 | // If we see a -moz-text element, we shouldn't look further up the parent |
5076 | 0 | // chain! |
5077 | 0 | break; |
5078 | 0 | } |
5079 | 0 | if (userSelect == StyleUserSelect::All || |
5080 | 0 | frame->IsGeneratedContentFrame()) { |
5081 | 0 | adjustedFrame = frame; |
5082 | 0 | } |
5083 | 0 | } |
5084 | 0 | return adjustedFrame; |
5085 | 0 | } |
5086 | | |
5087 | | nsIFrame::ContentOffsets nsIFrame::GetContentOffsetsFromPoint(const nsPoint& aPoint, |
5088 | | uint32_t aFlags) |
5089 | 0 | { |
5090 | 0 | nsIFrame *adjustedFrame; |
5091 | 0 | if (aFlags & IGNORE_SELECTION_STYLE) { |
5092 | 0 | adjustedFrame = this; |
5093 | 0 | } |
5094 | 0 | else { |
5095 | 0 | // This section of code deals with special selection styles. Note that |
5096 | 0 | // -moz-all exists, even though it doesn't need to be explicitly handled. |
5097 | 0 | // |
5098 | 0 | // The offset is forced not to end up in generated content; content offsets |
5099 | 0 | // cannot represent content outside of the document's content tree. |
5100 | 0 |
|
5101 | 0 | adjustedFrame = AdjustFrameForSelectionStyles(this); |
5102 | 0 |
|
5103 | 0 | // -moz-user-select: all needs special handling, because clicking on it |
5104 | 0 | // should lead to the whole frame being selected |
5105 | 0 | if (adjustedFrame && adjustedFrame->StyleUIReset()->mUserSelect == |
5106 | 0 | StyleUserSelect::All) { |
5107 | 0 | nsPoint adjustedPoint = aPoint + this->GetOffsetTo(adjustedFrame); |
5108 | 0 | return OffsetsForSingleFrame(adjustedFrame, adjustedPoint); |
5109 | 0 | } |
5110 | 0 | |
5111 | 0 | // For other cases, try to find a closest frame starting from the parent of |
5112 | 0 | // the unselectable frame |
5113 | 0 | if (adjustedFrame != this) |
5114 | 0 | adjustedFrame = adjustedFrame->GetParent(); |
5115 | 0 | } |
5116 | 0 |
|
5117 | 0 | nsPoint adjustedPoint = aPoint + this->GetOffsetTo(adjustedFrame); |
5118 | 0 |
|
5119 | 0 | FrameTarget closest = |
5120 | 0 | GetSelectionClosestFrame(adjustedFrame, adjustedPoint, aFlags); |
5121 | 0 |
|
5122 | 0 | // If the correct offset is at one end of a frame, use offset-based |
5123 | 0 | // calculation method |
5124 | 0 | if (closest.frameEdge) { |
5125 | 0 | ContentOffsets offsets; |
5126 | 0 | FrameContentRange range = GetRangeForFrame(closest.frame); |
5127 | 0 | offsets.content = range.content; |
5128 | 0 | if (closest.afterFrame) |
5129 | 0 | offsets.offset = range.end; |
5130 | 0 | else |
5131 | 0 | offsets.offset = range.start; |
5132 | 0 | offsets.secondaryOffset = offsets.offset; |
5133 | 0 | offsets.associate = offsets.offset == range.start ? |
5134 | 0 | CARET_ASSOCIATE_AFTER : CARET_ASSOCIATE_BEFORE; |
5135 | 0 | return offsets; |
5136 | 0 | } |
5137 | 0 |
|
5138 | 0 | nsPoint pt; |
5139 | 0 | if (closest.frame != this) { |
5140 | 0 | if (nsSVGUtils::IsInSVGTextSubtree(closest.frame)) { |
5141 | 0 | pt = nsLayoutUtils::TransformAncestorPointToFrame(closest.frame, |
5142 | 0 | aPoint, this); |
5143 | 0 | } else { |
5144 | 0 | pt = aPoint - closest.frame->GetOffsetTo(this); |
5145 | 0 | } |
5146 | 0 | } else { |
5147 | 0 | pt = aPoint; |
5148 | 0 | } |
5149 | 0 | return static_cast<nsFrame*>(closest.frame)->CalcContentOffsetsFromFramePoint(pt); |
5150 | 0 |
|
5151 | 0 | // XXX should I add some kind of offset standardization? |
5152 | 0 | // consider <b>xxxxx</b><i>zzzzz</i>; should any click between the last |
5153 | 0 | // x and first z put the cursor in the same logical position in addition |
5154 | 0 | // to the same visual position? |
5155 | 0 | } |
5156 | | |
5157 | | nsIFrame::ContentOffsets nsFrame::CalcContentOffsetsFromFramePoint(const nsPoint& aPoint) |
5158 | 0 | { |
5159 | 0 | return OffsetsForSingleFrame(this, aPoint); |
5160 | 0 | } |
5161 | | |
5162 | | void |
5163 | | nsIFrame::AssociateImage(const nsStyleImage& aImage, nsPresContext* aPresContext, |
5164 | | uint32_t aImageLoaderFlags) |
5165 | 0 | { |
5166 | 0 | if (aImage.GetType() != eStyleImageType_Image) { |
5167 | 0 | return; |
5168 | 0 | } |
5169 | 0 | |
5170 | 0 | imgRequestProxy* req = aImage.GetImageData(); |
5171 | 0 | if (!req) { |
5172 | 0 | return; |
5173 | 0 | } |
5174 | 0 | mozilla::css::ImageLoader* loader = |
5175 | 0 | aPresContext->Document()->StyleImageLoader(); |
5176 | 0 |
|
5177 | 0 | // If this fails there's not much we can do ... |
5178 | 0 | loader->AssociateRequestToFrame(req, this, aImageLoaderFlags); |
5179 | 0 | } |
5180 | | |
5181 | | nsresult |
5182 | | nsFrame::GetCursor(const nsPoint& aPoint, |
5183 | | nsIFrame::Cursor& aCursor) |
5184 | 0 | { |
5185 | 0 | FillCursorInformationFromStyle(StyleUI(), aCursor); |
5186 | 0 | if (NS_STYLE_CURSOR_AUTO == aCursor.mCursor) { |
5187 | 0 | // If this is editable, I-beam cursor is better for most elements. |
5188 | 0 | aCursor.mCursor = |
5189 | 0 | (mContent && mContent->IsEditable()) |
5190 | 0 | ? NS_STYLE_CURSOR_TEXT : NS_STYLE_CURSOR_DEFAULT; |
5191 | 0 | } |
5192 | 0 | if (NS_STYLE_CURSOR_TEXT == aCursor.mCursor && |
5193 | 0 | GetWritingMode().IsVertical()) { |
5194 | 0 | // Per CSS UI spec, UA may treat value 'text' as |
5195 | 0 | // 'vertical-text' for vertical text. |
5196 | 0 | aCursor.mCursor = NS_STYLE_CURSOR_VERTICAL_TEXT; |
5197 | 0 | } |
5198 | 0 |
|
5199 | 0 | return NS_OK; |
5200 | 0 | } |
5201 | | |
5202 | | // Resize and incremental reflow |
5203 | | |
5204 | | /* virtual */ void |
5205 | | nsFrame::MarkIntrinsicISizesDirty() |
5206 | 0 | { |
5207 | 0 | // This version is meant only for what used to be box-to-block adaptors. |
5208 | 0 | // It should not be called by other derived classes. |
5209 | 0 | if (::IsXULBoxWrapped(this)) { |
5210 | 0 | nsBoxLayoutMetrics *metrics = BoxMetrics(); |
5211 | 0 |
|
5212 | 0 | SizeNeedsRecalc(metrics->mPrefSize); |
5213 | 0 | SizeNeedsRecalc(metrics->mMinSize); |
5214 | 0 | SizeNeedsRecalc(metrics->mMaxSize); |
5215 | 0 | SizeNeedsRecalc(metrics->mBlockPrefSize); |
5216 | 0 | SizeNeedsRecalc(metrics->mBlockMinSize); |
5217 | 0 | CoordNeedsRecalc(metrics->mFlex); |
5218 | 0 | CoordNeedsRecalc(metrics->mAscent); |
5219 | 0 | } |
5220 | 0 |
|
5221 | 0 | // If we're a flex item, clear our flex-item-specific cached measurements |
5222 | 0 | // (which likely depended on our now-stale intrinsic isize). |
5223 | 0 | auto* parentFrame = GetParent(); |
5224 | 0 | if (parentFrame && parentFrame->IsFlexContainerFrame()) { |
5225 | 0 | DeleteProperty(CachedFlexMeasuringReflow()); |
5226 | 0 | } |
5227 | 0 |
|
5228 | 0 | if (GetStateBits() & NS_FRAME_FONT_INFLATION_FLOW_ROOT) { |
5229 | 0 | nsFontInflationData::MarkFontInflationDataTextDirty(this); |
5230 | 0 | } |
5231 | 0 | } |
5232 | | |
5233 | | /* virtual */ nscoord |
5234 | | nsFrame::GetMinISize(gfxContext *aRenderingContext) |
5235 | 0 | { |
5236 | 0 | nscoord result = 0; |
5237 | 0 | DISPLAY_MIN_INLINE_SIZE(this, result); |
5238 | 0 | return result; |
5239 | 0 | } |
5240 | | |
5241 | | /* virtual */ nscoord |
5242 | | nsFrame::GetPrefISize(gfxContext *aRenderingContext) |
5243 | 0 | { |
5244 | 0 | nscoord result = 0; |
5245 | 0 | DISPLAY_PREF_INLINE_SIZE(this, result); |
5246 | 0 | return result; |
5247 | 0 | } |
5248 | | |
5249 | | /* virtual */ void |
5250 | | nsFrame::AddInlineMinISize(gfxContext* aRenderingContext, |
5251 | | nsIFrame::InlineMinISizeData* aData) |
5252 | 0 | { |
5253 | 0 | nscoord isize = nsLayoutUtils::IntrinsicForContainer(aRenderingContext, |
5254 | 0 | this, nsLayoutUtils::MIN_ISIZE); |
5255 | 0 | aData->DefaultAddInlineMinISize(this, isize); |
5256 | 0 | } |
5257 | | |
5258 | | /* virtual */ void |
5259 | | nsFrame::AddInlinePrefISize(gfxContext* aRenderingContext, |
5260 | | nsIFrame::InlinePrefISizeData* aData) |
5261 | 0 | { |
5262 | 0 | nscoord isize = nsLayoutUtils::IntrinsicForContainer(aRenderingContext, |
5263 | 0 | this, nsLayoutUtils::PREF_ISIZE); |
5264 | 0 | aData->DefaultAddInlinePrefISize(isize); |
5265 | 0 | } |
5266 | | |
5267 | | void |
5268 | | nsIFrame::InlineMinISizeData::DefaultAddInlineMinISize(nsIFrame* aFrame, |
5269 | | nscoord aISize, |
5270 | | bool aAllowBreak) |
5271 | 0 | { |
5272 | 0 | auto parent = aFrame->GetParent(); |
5273 | 0 | MOZ_ASSERT(parent, "Must have a parent if we get here!"); |
5274 | 0 | const bool mayBreak = aAllowBreak && |
5275 | 0 | !aFrame->CanContinueTextRun() && |
5276 | 0 | !parent->Style()->ShouldSuppressLineBreak() && |
5277 | 0 | parent->StyleText()->WhiteSpaceCanWrap(parent); |
5278 | 0 | if (mayBreak) { |
5279 | 0 | OptionallyBreak(); |
5280 | 0 | } |
5281 | 0 | mTrailingWhitespace = 0; |
5282 | 0 | mSkipWhitespace = false; |
5283 | 0 | mCurrentLine += aISize; |
5284 | 0 | mAtStartOfLine = false; |
5285 | 0 | if (mayBreak) { |
5286 | 0 | OptionallyBreak(); |
5287 | 0 | } |
5288 | 0 | } |
5289 | | |
5290 | | void |
5291 | | nsIFrame::InlinePrefISizeData::DefaultAddInlinePrefISize(nscoord aISize) |
5292 | 0 | { |
5293 | 0 | mCurrentLine = NSCoordSaturatingAdd(mCurrentLine, aISize); |
5294 | 0 | mTrailingWhitespace = 0; |
5295 | 0 | mSkipWhitespace = false; |
5296 | 0 | mLineIsEmpty = false; |
5297 | 0 | } |
5298 | | |
5299 | | void |
5300 | | nsIFrame::InlineMinISizeData::ForceBreak() |
5301 | 0 | { |
5302 | 0 | mCurrentLine -= mTrailingWhitespace; |
5303 | 0 | mPrevLines = std::max(mPrevLines, mCurrentLine); |
5304 | 0 | mCurrentLine = mTrailingWhitespace = 0; |
5305 | 0 |
|
5306 | 0 | for (uint32_t i = 0, i_end = mFloats.Length(); i != i_end; ++i) { |
5307 | 0 | nscoord float_min = mFloats[i].Width(); |
5308 | 0 | if (float_min > mPrevLines) |
5309 | 0 | mPrevLines = float_min; |
5310 | 0 | } |
5311 | 0 | mFloats.Clear(); |
5312 | 0 | mSkipWhitespace = true; |
5313 | 0 | } |
5314 | | |
5315 | | void |
5316 | | nsIFrame::InlineMinISizeData::OptionallyBreak(nscoord aHyphenWidth) |
5317 | 0 | { |
5318 | 0 | // If we can fit more content into a smaller width by staying on this |
5319 | 0 | // line (because we're still at a negative offset due to negative |
5320 | 0 | // text-indent or negative margin), don't break. Otherwise, do the |
5321 | 0 | // same as ForceBreak. it doesn't really matter when we accumulate |
5322 | 0 | // floats. |
5323 | 0 | if (mCurrentLine + aHyphenWidth < 0 || mAtStartOfLine) |
5324 | 0 | return; |
5325 | 0 | mCurrentLine += aHyphenWidth; |
5326 | 0 | ForceBreak(); |
5327 | 0 | } |
5328 | | |
5329 | | void |
5330 | | nsIFrame::InlinePrefISizeData::ForceBreak(StyleClear aBreakType) |
5331 | 0 | { |
5332 | 0 | MOZ_ASSERT(aBreakType == StyleClear::None || |
5333 | 0 | aBreakType == StyleClear::Both || |
5334 | 0 | aBreakType == StyleClear::Left || |
5335 | 0 | aBreakType == StyleClear::Right, |
5336 | 0 | "Must be a physical break type"); |
5337 | 0 |
|
5338 | 0 | // If this force break is not clearing any float, we can leave all the |
5339 | 0 | // floats to the next force break. |
5340 | 0 | if (mFloats.Length() != 0 && aBreakType != StyleClear::None) { |
5341 | 0 | // preferred widths accumulated for floats that have already |
5342 | 0 | // been cleared past |
5343 | 0 | nscoord floats_done = 0, |
5344 | 0 | // preferred widths accumulated for floats that have not yet |
5345 | 0 | // been cleared past |
5346 | 0 | floats_cur_left = 0, |
5347 | 0 | floats_cur_right = 0; |
5348 | 0 |
|
5349 | 0 | for (uint32_t i = 0, i_end = mFloats.Length(); i != i_end; ++i) { |
5350 | 0 | const FloatInfo& floatInfo = mFloats[i]; |
5351 | 0 | const nsStyleDisplay* floatDisp = floatInfo.Frame()->StyleDisplay(); |
5352 | 0 | StyleClear breakType = floatDisp->mBreakType; |
5353 | 0 | if (breakType == StyleClear::Left || |
5354 | 0 | breakType == StyleClear::Right || |
5355 | 0 | breakType == StyleClear::Both) { |
5356 | 0 | nscoord floats_cur = NSCoordSaturatingAdd(floats_cur_left, |
5357 | 0 | floats_cur_right); |
5358 | 0 | if (floats_cur > floats_done) { |
5359 | 0 | floats_done = floats_cur; |
5360 | 0 | } |
5361 | 0 | if (breakType != StyleClear::Right) { |
5362 | 0 | floats_cur_left = 0; |
5363 | 0 | } |
5364 | 0 | if (breakType != StyleClear::Left) { |
5365 | 0 | floats_cur_right = 0; |
5366 | 0 | } |
5367 | 0 | } |
5368 | 0 |
|
5369 | 0 | StyleFloat floatStyle = floatDisp->mFloat; |
5370 | 0 | nscoord& floats_cur = |
5371 | 0 | floatStyle == StyleFloat::Left ? floats_cur_left : floats_cur_right; |
5372 | 0 | nscoord floatWidth = floatInfo.Width(); |
5373 | 0 | // Negative-width floats don't change the available space so they |
5374 | 0 | // shouldn't change our intrinsic line width either. |
5375 | 0 | floats_cur = |
5376 | 0 | NSCoordSaturatingAdd(floats_cur, std::max(0, floatWidth)); |
5377 | 0 | } |
5378 | 0 |
|
5379 | 0 | nscoord floats_cur = |
5380 | 0 | NSCoordSaturatingAdd(floats_cur_left, floats_cur_right); |
5381 | 0 | if (floats_cur > floats_done) |
5382 | 0 | floats_done = floats_cur; |
5383 | 0 |
|
5384 | 0 | mCurrentLine = NSCoordSaturatingAdd(mCurrentLine, floats_done); |
5385 | 0 |
|
5386 | 0 | if (aBreakType == StyleClear::Both) { |
5387 | 0 | mFloats.Clear(); |
5388 | 0 | } else { |
5389 | 0 | // If the break type does not clear all floats, it means there may |
5390 | 0 | // be some floats whose isize should contribute to the intrinsic |
5391 | 0 | // isize of the next line. The code here scans the current mFloats |
5392 | 0 | // and keeps floats which are not cleared by this break. Note that |
5393 | 0 | // floats may be cleared directly or indirectly. See below. |
5394 | 0 | nsTArray<FloatInfo> newFloats; |
5395 | 0 | MOZ_ASSERT(aBreakType == StyleClear::Left || |
5396 | 0 | aBreakType == StyleClear::Right, |
5397 | 0 | "Other values should have been handled in other branches"); |
5398 | 0 | StyleFloat clearFloatType = |
5399 | 0 | aBreakType == StyleClear::Left ? StyleFloat::Left : StyleFloat::Right; |
5400 | 0 | // Iterate the array in reverse so that we can stop when there are |
5401 | 0 | // no longer any floats we need to keep. See below. |
5402 | 0 | for (FloatInfo& floatInfo : Reversed(mFloats)) { |
5403 | 0 | const nsStyleDisplay* floatDisp = floatInfo.Frame()->StyleDisplay(); |
5404 | 0 | if (floatDisp->mFloat != clearFloatType) { |
5405 | 0 | newFloats.AppendElement(floatInfo); |
5406 | 0 | } else { |
5407 | 0 | // This is a float on the side that this break directly clears |
5408 | 0 | // which means we're not keeping it in mFloats. However, if |
5409 | 0 | // this float clears floats on the opposite side (via a value |
5410 | 0 | // of either 'both' or one of 'left'/'right'), any remaining |
5411 | 0 | // (earlier) floats on that side would be indirectly cleared |
5412 | 0 | // as well. Thus, we should break out of this loop and stop |
5413 | 0 | // considering earlier floats to be kept in mFloats. |
5414 | 0 | StyleClear floatBreakType = floatDisp->mBreakType; |
5415 | 0 | if (floatBreakType != aBreakType && |
5416 | 0 | floatBreakType != StyleClear::None) { |
5417 | 0 | break; |
5418 | 0 | } |
5419 | 0 | } |
5420 | 0 | } |
5421 | 0 | newFloats.Reverse(); |
5422 | 0 | mFloats = std::move(newFloats); |
5423 | 0 | } |
5424 | 0 | } |
5425 | 0 |
|
5426 | 0 | mCurrentLine = |
5427 | 0 | NSCoordSaturatingSubtract(mCurrentLine, mTrailingWhitespace, nscoord_MAX); |
5428 | 0 | mPrevLines = std::max(mPrevLines, mCurrentLine); |
5429 | 0 | mCurrentLine = mTrailingWhitespace = 0; |
5430 | 0 | mSkipWhitespace = true; |
5431 | 0 | mLineIsEmpty = true; |
5432 | 0 | } |
5433 | | |
5434 | | static nscoord |
5435 | | ResolveMargin(const nsStyleCoord& aStyle, nscoord aPercentageBasis) |
5436 | 0 | { |
5437 | 0 | if (aStyle.GetUnit() == eStyleUnit_Auto) { |
5438 | 0 | return nscoord(0); |
5439 | 0 | } |
5440 | 0 | return nsLayoutUtils::ResolveToLength<false>(aStyle, aPercentageBasis); |
5441 | 0 | } |
5442 | | |
5443 | | static nscoord |
5444 | | ResolvePadding(const nsStyleCoord& aStyle, nscoord aPercentageBasis) |
5445 | 0 | { |
5446 | 0 | return nsLayoutUtils::ResolveToLength<true>(aStyle, aPercentageBasis); |
5447 | 0 | } |
5448 | | |
5449 | | static nsIFrame::IntrinsicISizeOffsetData |
5450 | | IntrinsicSizeOffsets(nsIFrame* aFrame, nscoord aPercentageBasis, bool aForISize) |
5451 | 0 | { |
5452 | 0 | nsIFrame::IntrinsicISizeOffsetData result; |
5453 | 0 | WritingMode wm = aFrame->GetWritingMode(); |
5454 | 0 | const auto& margin = aFrame->StyleMargin()->mMargin; |
5455 | 0 | bool verticalAxis = aForISize == wm.IsVertical(); |
5456 | 0 | if (verticalAxis) { |
5457 | 0 | result.hMargin += ResolveMargin(margin.GetTop(), aPercentageBasis); |
5458 | 0 | result.hMargin += ResolveMargin(margin.GetBottom(), aPercentageBasis); |
5459 | 0 | } else { |
5460 | 0 | result.hMargin += ResolveMargin(margin.GetLeft(), aPercentageBasis); |
5461 | 0 | result.hMargin += ResolveMargin(margin.GetRight(), aPercentageBasis); |
5462 | 0 | } |
5463 | 0 |
|
5464 | 0 | const auto& padding = aFrame->StylePadding()->mPadding; |
5465 | 0 | if (verticalAxis) { |
5466 | 0 | result.hPadding += ResolvePadding(padding.GetTop(), aPercentageBasis); |
5467 | 0 | result.hPadding += ResolvePadding(padding.GetBottom(), aPercentageBasis); |
5468 | 0 | } else { |
5469 | 0 | result.hPadding += ResolvePadding(padding.GetLeft(), aPercentageBasis); |
5470 | 0 | result.hPadding += ResolvePadding(padding.GetRight(), aPercentageBasis); |
5471 | 0 | } |
5472 | 0 |
|
5473 | 0 | const nsStyleBorder* styleBorder = aFrame->StyleBorder(); |
5474 | 0 | if (verticalAxis) { |
5475 | 0 | result.hBorder += styleBorder->GetComputedBorderWidth(eSideTop); |
5476 | 0 | result.hBorder += styleBorder->GetComputedBorderWidth(eSideBottom); |
5477 | 0 | } else { |
5478 | 0 | result.hBorder += styleBorder->GetComputedBorderWidth(eSideLeft); |
5479 | 0 | result.hBorder += styleBorder->GetComputedBorderWidth(eSideRight); |
5480 | 0 | } |
5481 | 0 |
|
5482 | 0 | const nsStyleDisplay* disp = aFrame->StyleDisplay(); |
5483 | 0 | if (aFrame->IsThemed(disp)) { |
5484 | 0 | nsPresContext* presContext = aFrame->PresContext(); |
5485 | 0 |
|
5486 | 0 | LayoutDeviceIntMargin border = |
5487 | 0 | presContext->GetTheme()->GetWidgetBorder(presContext->DeviceContext(), |
5488 | 0 | aFrame, disp->mAppearance); |
5489 | 0 | result.hBorder = |
5490 | 0 | presContext->DevPixelsToAppUnits(verticalAxis ? border.TopBottom() |
5491 | 0 | : border.LeftRight()); |
5492 | 0 |
|
5493 | 0 | LayoutDeviceIntMargin padding; |
5494 | 0 | if (presContext->GetTheme()->GetWidgetPadding(presContext->DeviceContext(), |
5495 | 0 | aFrame, disp->mAppearance, |
5496 | 0 | &padding)) { |
5497 | 0 | result.hPadding = |
5498 | 0 | presContext->DevPixelsToAppUnits(verticalAxis ? padding.TopBottom() |
5499 | 0 | : padding.LeftRight()); |
5500 | 0 | } |
5501 | 0 | } |
5502 | 0 | return result; |
5503 | 0 | } |
5504 | | |
5505 | | /* virtual */ nsIFrame::IntrinsicISizeOffsetData |
5506 | | nsFrame::IntrinsicISizeOffsets(nscoord aPercentageBasis) |
5507 | 0 | { |
5508 | 0 | return IntrinsicSizeOffsets(this, aPercentageBasis, true); |
5509 | 0 | } |
5510 | | |
5511 | | nsIFrame::IntrinsicISizeOffsetData |
5512 | | nsIFrame::IntrinsicBSizeOffsets(nscoord aPercentageBasis) |
5513 | 0 | { |
5514 | 0 | return IntrinsicSizeOffsets(this, aPercentageBasis, false); |
5515 | 0 | } |
5516 | | |
5517 | | /* virtual */ IntrinsicSize |
5518 | | nsFrame::GetIntrinsicSize() |
5519 | 0 | { |
5520 | 0 | return IntrinsicSize(); // default is width/height set to eStyleUnit_None |
5521 | 0 | } |
5522 | | |
5523 | | /* virtual */ nsSize |
5524 | | nsFrame::GetIntrinsicRatio() |
5525 | 0 | { |
5526 | 0 | return nsSize(0, 0); |
5527 | 0 | } |
5528 | | |
5529 | | /* virtual */ |
5530 | | LogicalSize |
5531 | | nsFrame::ComputeSize(gfxContext* aRenderingContext, |
5532 | | WritingMode aWM, |
5533 | | const LogicalSize& aCBSize, |
5534 | | nscoord aAvailableISize, |
5535 | | const LogicalSize& aMargin, |
5536 | | const LogicalSize& aBorder, |
5537 | | const LogicalSize& aPadding, |
5538 | | ComputeSizeFlags aFlags) |
5539 | 0 | { |
5540 | 0 | MOZ_ASSERT(GetIntrinsicRatio() == nsSize(0,0), |
5541 | 0 | "Please override this method and call " |
5542 | 0 | "nsFrame::ComputeSizeWithIntrinsicDimensions instead."); |
5543 | 0 | LogicalSize result = ComputeAutoSize(aRenderingContext, aWM, |
5544 | 0 | aCBSize, aAvailableISize, |
5545 | 0 | aMargin, aBorder, aPadding, |
5546 | 0 | aFlags); |
5547 | 0 | const nsStylePosition *stylePos = StylePosition(); |
5548 | 0 |
|
5549 | 0 | LogicalSize boxSizingAdjust(aWM); |
5550 | 0 | if (stylePos->mBoxSizing == StyleBoxSizing::Border) { |
5551 | 0 | boxSizingAdjust = aBorder + aPadding; |
5552 | 0 | } |
5553 | 0 | nscoord boxSizingToMarginEdgeISize = |
5554 | 0 | aMargin.ISize(aWM) + aBorder.ISize(aWM) + aPadding.ISize(aWM) - |
5555 | 0 | boxSizingAdjust.ISize(aWM); |
5556 | 0 |
|
5557 | 0 | const nsStyleCoord* inlineStyleCoord = &stylePos->ISize(aWM); |
5558 | 0 | const nsStyleCoord* blockStyleCoord = &stylePos->BSize(aWM); |
5559 | 0 |
|
5560 | 0 | auto parentFrame = GetParent(); |
5561 | 0 | auto alignCB = parentFrame; |
5562 | 0 | bool isGridItem = parentFrame && parentFrame->IsGridContainerFrame() && |
5563 | 0 | !HasAnyStateBits(NS_FRAME_OUT_OF_FLOW); |
5564 | 0 | if (parentFrame && parentFrame->IsTableWrapperFrame() && IsTableFrame()) { |
5565 | 0 | // An inner table frame is sized as a grid item if its table wrapper is, |
5566 | 0 | // because they actually have the same CB (the wrapper's CB). |
5567 | 0 | // @see ReflowInput::InitCBReflowInput |
5568 | 0 | auto tableWrapper = GetParent(); |
5569 | 0 | auto grandParent = tableWrapper->GetParent(); |
5570 | 0 | isGridItem = (grandParent->IsGridContainerFrame() && |
5571 | 0 | !(tableWrapper->GetStateBits() & NS_FRAME_OUT_OF_FLOW)); |
5572 | 0 | if (isGridItem) { |
5573 | 0 | // When resolving justify/align-self below, we want to use the grid |
5574 | 0 | // container's justify/align-items value and WritingMode. |
5575 | 0 | alignCB = grandParent; |
5576 | 0 | } |
5577 | 0 | } |
5578 | 0 | bool isFlexItem = parentFrame && parentFrame->IsFlexContainerFrame() && |
5579 | 0 | !parentFrame->HasAnyStateBits(NS_STATE_FLEX_IS_EMULATING_LEGACY_BOX) && |
5580 | 0 | !HasAnyStateBits(NS_FRAME_OUT_OF_FLOW); |
5581 | 0 | // This variable only gets set (and used) if isFlexItem is true. It |
5582 | 0 | // indicates which axis (in this frame's own WM) corresponds to its |
5583 | 0 | // flex container's main axis. |
5584 | 0 | LogicalAxis flexMainAxis = eLogicalAxisInline; // (init to make valgrind happy) |
5585 | 0 | if (isFlexItem) { |
5586 | 0 | // Flex items use their "flex-basis" property in place of their main-size |
5587 | 0 | // property for sizing purposes, *unless* they have "flex-basis:auto", in |
5588 | 0 | // which case they use their main-size property after all. |
5589 | 0 | flexMainAxis = nsFlexContainerFrame::IsItemInlineAxisMainAxis(this) ? |
5590 | 0 | eLogicalAxisInline : eLogicalAxisBlock; |
5591 | 0 |
|
5592 | 0 | // NOTE: The logic here should match the similar chunk for updating |
5593 | 0 | // mainAxisCoord in nsFrame::ComputeSizeWithIntrinsicDimensions() (aside |
5594 | 0 | // from using a different dummy value in the IsUsedFlexBasisContent() case). |
5595 | 0 | const nsStyleCoord* flexBasis = &(stylePos->mFlexBasis); |
5596 | 0 | auto& mainAxisCoord = (flexMainAxis == eLogicalAxisInline |
5597 | 0 | ? inlineStyleCoord : blockStyleCoord); |
5598 | 0 |
|
5599 | 0 | // NOTE: If we're a table-wrapper frame, we skip this clause and just stick |
5600 | 0 | // with 'main-size:auto' behavior (which -- unlike 'content' |
5601 | 0 | // i.e. 'max-content' -- will give us the ability to honor percent sizes on |
5602 | 0 | // our table-box child when resolving the flex base size). The flexbox spec |
5603 | 0 | // doesn't call for this special case, but webcompat & regression-avoidance |
5604 | 0 | // seems to require it, for the time being... Tables sure are special. |
5605 | 0 | if (nsFlexContainerFrame::IsUsedFlexBasisContent(flexBasis, |
5606 | 0 | mainAxisCoord) && |
5607 | 0 | MOZ_LIKELY(!IsTableWrapperFrame())) { |
5608 | 0 | static const nsStyleCoord maxContStyleCoord(NS_STYLE_WIDTH_MAX_CONTENT, |
5609 | 0 | eStyleUnit_Enumerated); |
5610 | 0 | mainAxisCoord = &maxContStyleCoord; |
5611 | 0 | // (Note: if our main axis is the block axis, then this 'max-content' |
5612 | 0 | // value will be treated like 'auto', via the IsAutoBSize() call below.) |
5613 | 0 | } else if (flexBasis->GetUnit() != eStyleUnit_Auto) { |
5614 | 0 | // For all other non-'auto' flex-basis values, we just swap in the |
5615 | 0 | // flex-basis itself for the main-size property. |
5616 | 0 | mainAxisCoord = flexBasis; |
5617 | 0 | } // else: flex-basis is 'auto', which is deferring to some explicit value |
5618 | 0 | // in mainAxisCoord. So we proceed w/o touching mainAxisCoord. |
5619 | 0 | } |
5620 | 0 |
|
5621 | 0 | // Compute inline-axis size |
5622 | 0 | if (inlineStyleCoord->GetUnit() != eStyleUnit_Auto) { |
5623 | 0 | result.ISize(aWM) = |
5624 | 0 | ComputeISizeValue(aRenderingContext, aCBSize.ISize(aWM), |
5625 | 0 | boxSizingAdjust.ISize(aWM), boxSizingToMarginEdgeISize, |
5626 | 0 | *inlineStyleCoord, aFlags); |
5627 | 0 | } else if (MOZ_UNLIKELY(isGridItem) && |
5628 | 0 | !IS_TRUE_OVERFLOW_CONTAINER(this)) { |
5629 | 0 | // 'auto' inline-size for grid-level box - fill the CB for 'stretch' / |
5630 | 0 | // 'normal' and clamp it to the CB if requested: |
5631 | 0 | bool stretch = false; |
5632 | 0 | if (!(aFlags & nsIFrame::eShrinkWrap) && |
5633 | 0 | !StyleMargin()->HasInlineAxisAuto(aWM)) { |
5634 | 0 | auto inlineAxisAlignment = |
5635 | 0 | aWM.IsOrthogonalTo(alignCB->GetWritingMode()) ? |
5636 | 0 | StylePosition()->UsedAlignSelf(alignCB->Style()) : |
5637 | 0 | StylePosition()->UsedJustifySelf(alignCB->Style()); |
5638 | 0 | stretch = inlineAxisAlignment == NS_STYLE_ALIGN_NORMAL || |
5639 | 0 | inlineAxisAlignment == NS_STYLE_ALIGN_STRETCH; |
5640 | 0 | } |
5641 | 0 | if (stretch || (aFlags & ComputeSizeFlags::eIClampMarginBoxMinSize)) { |
5642 | 0 | auto iSizeToFillCB = std::max(nscoord(0), aCBSize.ISize(aWM) - |
5643 | 0 | aPadding.ISize(aWM) - |
5644 | 0 | aBorder.ISize(aWM) - |
5645 | 0 | aMargin.ISize(aWM)); |
5646 | 0 | if (stretch || result.ISize(aWM) > iSizeToFillCB) { |
5647 | 0 | result.ISize(aWM) = iSizeToFillCB; |
5648 | 0 | } |
5649 | 0 | } |
5650 | 0 | } |
5651 | 0 |
|
5652 | 0 | // Flex items ignore their min & max sizing properties in their |
5653 | 0 | // flex container's main-axis. (Those properties get applied later in |
5654 | 0 | // the flexbox algorithm.) |
5655 | 0 | const nsStyleCoord& maxISizeCoord = stylePos->MaxISize(aWM); |
5656 | 0 | nscoord maxISize = NS_UNCONSTRAINEDSIZE; |
5657 | 0 | if (maxISizeCoord.GetUnit() != eStyleUnit_None && |
5658 | 0 | !(isFlexItem && flexMainAxis == eLogicalAxisInline)) { |
5659 | 0 | maxISize = |
5660 | 0 | ComputeISizeValue(aRenderingContext, aCBSize.ISize(aWM), |
5661 | 0 | boxSizingAdjust.ISize(aWM), boxSizingToMarginEdgeISize, |
5662 | 0 | maxISizeCoord, aFlags); |
5663 | 0 | result.ISize(aWM) = std::min(maxISize, result.ISize(aWM)); |
5664 | 0 | } |
5665 | 0 |
|
5666 | 0 | const nsStyleCoord& minISizeCoord = stylePos->MinISize(aWM); |
5667 | 0 | nscoord minISize; |
5668 | 0 | if (minISizeCoord.GetUnit() != eStyleUnit_Auto && |
5669 | 0 | !(isFlexItem && flexMainAxis == eLogicalAxisInline)) { |
5670 | 0 | minISize = |
5671 | 0 | ComputeISizeValue(aRenderingContext, aCBSize.ISize(aWM), |
5672 | 0 | boxSizingAdjust.ISize(aWM), boxSizingToMarginEdgeISize, |
5673 | 0 | minISizeCoord, aFlags); |
5674 | 0 | } else if (MOZ_UNLIKELY(aFlags & eIApplyAutoMinSize)) { |
5675 | 0 | // This implements "Implied Minimum Size of Grid Items". |
5676 | 0 | // https://drafts.csswg.org/css-grid/#min-size-auto |
5677 | 0 | minISize = std::min(maxISize, GetMinISize(aRenderingContext)); |
5678 | 0 | if (inlineStyleCoord->IsCoordPercentCalcUnit()) { |
5679 | 0 | minISize = std::min(minISize, result.ISize(aWM)); |
5680 | 0 | } else if (aFlags & eIClampMarginBoxMinSize) { |
5681 | 0 | // "if the grid item spans only grid tracks that have a fixed max track |
5682 | 0 | // sizing function, its automatic minimum size in that dimension is |
5683 | 0 | // further clamped to less than or equal to the size necessary to fit |
5684 | 0 | // its margin box within the resulting grid area (flooring at zero)" |
5685 | 0 | // https://drafts.csswg.org/css-grid/#min-size-auto |
5686 | 0 | auto maxMinISize = std::max(nscoord(0), aCBSize.ISize(aWM) - |
5687 | 0 | aPadding.ISize(aWM) - |
5688 | 0 | aBorder.ISize(aWM) - |
5689 | 0 | aMargin.ISize(aWM)); |
5690 | 0 | minISize = std::min(minISize, maxMinISize); |
5691 | 0 | } |
5692 | 0 | } else { |
5693 | 0 | // Treat "min-width: auto" as 0. |
5694 | 0 | // NOTE: Technically, "auto" is supposed to behave like "min-content" on |
5695 | 0 | // flex items. However, we don't need to worry about that here, because |
5696 | 0 | // flex items' min-sizes are intentionally ignored until the flex |
5697 | 0 | // container explicitly considers them during space distribution. |
5698 | 0 | minISize = 0; |
5699 | 0 | } |
5700 | 0 | result.ISize(aWM) = std::max(minISize, result.ISize(aWM)); |
5701 | 0 |
|
5702 | 0 | // Compute block-axis size |
5703 | 0 | // (but not if we have auto bsize or if we received the "eUseAutoBSize" |
5704 | 0 | // flag -- then, we'll just stick with the bsize that we already calculated |
5705 | 0 | // in the initial ComputeAutoSize() call.) |
5706 | 0 | if (!(aFlags & nsIFrame::eUseAutoBSize)) { |
5707 | 0 | if (!nsLayoutUtils::IsAutoBSize(*blockStyleCoord, aCBSize.BSize(aWM))) { |
5708 | 0 | result.BSize(aWM) = |
5709 | 0 | nsLayoutUtils::ComputeBSizeValue(aCBSize.BSize(aWM), |
5710 | 0 | boxSizingAdjust.BSize(aWM), |
5711 | 0 | *blockStyleCoord); |
5712 | 0 | } else if (MOZ_UNLIKELY(isGridItem) && |
5713 | 0 | blockStyleCoord->GetUnit() == eStyleUnit_Auto && |
5714 | 0 | !IS_TRUE_OVERFLOW_CONTAINER(this)) { |
5715 | 0 | auto cbSize = aCBSize.BSize(aWM); |
5716 | 0 | if (cbSize != NS_AUTOHEIGHT) { |
5717 | 0 | // 'auto' block-size for grid-level box - fill the CB for 'stretch' / |
5718 | 0 | // 'normal' and clamp it to the CB if requested: |
5719 | 0 | bool stretch = false; |
5720 | 0 | if (!StyleMargin()->HasBlockAxisAuto(aWM)) { |
5721 | 0 | auto blockAxisAlignment = |
5722 | 0 | !aWM.IsOrthogonalTo(alignCB->GetWritingMode()) ? |
5723 | 0 | StylePosition()->UsedAlignSelf(alignCB->Style()) : |
5724 | 0 | StylePosition()->UsedJustifySelf(alignCB->Style()); |
5725 | 0 | stretch = blockAxisAlignment == NS_STYLE_ALIGN_NORMAL || |
5726 | 0 | blockAxisAlignment == NS_STYLE_ALIGN_STRETCH; |
5727 | 0 | } |
5728 | 0 | if (stretch || (aFlags & ComputeSizeFlags::eBClampMarginBoxMinSize)) { |
5729 | 0 | auto bSizeToFillCB = std::max(nscoord(0), cbSize - |
5730 | 0 | aPadding.BSize(aWM) - |
5731 | 0 | aBorder.BSize(aWM) - |
5732 | 0 | aMargin.BSize(aWM)); |
5733 | 0 | if (stretch || (result.BSize(aWM) != NS_AUTOHEIGHT && |
5734 | 0 | result.BSize(aWM) > bSizeToFillCB)) { |
5735 | 0 | result.BSize(aWM) = bSizeToFillCB; |
5736 | 0 | } |
5737 | 0 | } |
5738 | 0 | } |
5739 | 0 | } |
5740 | 0 | } |
5741 | 0 |
|
5742 | 0 | const nsStyleCoord& maxBSizeCoord = stylePos->MaxBSize(aWM); |
5743 | 0 |
|
5744 | 0 | if (result.BSize(aWM) != NS_UNCONSTRAINEDSIZE) { |
5745 | 0 | if (!nsLayoutUtils::IsAutoBSize(maxBSizeCoord, aCBSize.BSize(aWM)) && |
5746 | 0 | !(isFlexItem && flexMainAxis == eLogicalAxisBlock)) { |
5747 | 0 | nscoord maxBSize = |
5748 | 0 | nsLayoutUtils::ComputeBSizeValue(aCBSize.BSize(aWM), |
5749 | 0 | boxSizingAdjust.BSize(aWM), |
5750 | 0 | maxBSizeCoord); |
5751 | 0 | result.BSize(aWM) = std::min(maxBSize, result.BSize(aWM)); |
5752 | 0 | } |
5753 | 0 |
|
5754 | 0 | const nsStyleCoord& minBSizeCoord = stylePos->MinBSize(aWM); |
5755 | 0 |
|
5756 | 0 | if (!nsLayoutUtils::IsAutoBSize(minBSizeCoord, aCBSize.BSize(aWM)) && |
5757 | 0 | !(isFlexItem && flexMainAxis == eLogicalAxisBlock)) { |
5758 | 0 | nscoord minBSize = |
5759 | 0 | nsLayoutUtils::ComputeBSizeValue(aCBSize.BSize(aWM), |
5760 | 0 | boxSizingAdjust.BSize(aWM), |
5761 | 0 | minBSizeCoord); |
5762 | 0 | result.BSize(aWM) = std::max(minBSize, result.BSize(aWM)); |
5763 | 0 | } |
5764 | 0 | } |
5765 | 0 |
|
5766 | 0 | const nsStyleDisplay *disp = StyleDisplay(); |
5767 | 0 | if (IsThemed(disp)) { |
5768 | 0 | LayoutDeviceIntSize widget; |
5769 | 0 | bool canOverride = true; |
5770 | 0 | nsPresContext *presContext = PresContext(); |
5771 | 0 | presContext->GetTheme()-> |
5772 | 0 | GetMinimumWidgetSize(presContext, this, disp->mAppearance, |
5773 | 0 | &widget, &canOverride); |
5774 | 0 |
|
5775 | 0 | // Convert themed widget's physical dimensions to logical coords |
5776 | 0 | LogicalSize size(aWM, |
5777 | 0 | nsSize(presContext->DevPixelsToAppUnits(widget.width), |
5778 | 0 | presContext->DevPixelsToAppUnits(widget.height))); |
5779 | 0 |
|
5780 | 0 | // GMWS() returns border-box; we need content-box |
5781 | 0 | size.ISize(aWM) -= aBorder.ISize(aWM) + aPadding.ISize(aWM); |
5782 | 0 | size.BSize(aWM) -= aBorder.BSize(aWM) + aPadding.BSize(aWM); |
5783 | 0 |
|
5784 | 0 | if (size.BSize(aWM) > result.BSize(aWM) || !canOverride) { |
5785 | 0 | result.BSize(aWM) = size.BSize(aWM); |
5786 | 0 | } |
5787 | 0 | if (size.ISize(aWM) > result.ISize(aWM) || !canOverride) { |
5788 | 0 | result.ISize(aWM) = size.ISize(aWM); |
5789 | 0 | } |
5790 | 0 | } |
5791 | 0 |
|
5792 | 0 | result.ISize(aWM) = std::max(0, result.ISize(aWM)); |
5793 | 0 | result.BSize(aWM) = std::max(0, result.BSize(aWM)); |
5794 | 0 |
|
5795 | 0 | return result; |
5796 | 0 | } |
5797 | | |
5798 | | LogicalSize |
5799 | | nsFrame::ComputeSizeWithIntrinsicDimensions(gfxContext* aRenderingContext, |
5800 | | WritingMode aWM, |
5801 | | const IntrinsicSize& aIntrinsicSize, |
5802 | | nsSize aIntrinsicRatio, |
5803 | | const LogicalSize& aCBSize, |
5804 | | const LogicalSize& aMargin, |
5805 | | const LogicalSize& aBorder, |
5806 | | const LogicalSize& aPadding, |
5807 | | ComputeSizeFlags aFlags) |
5808 | 0 | { |
5809 | 0 | const nsStylePosition* stylePos = StylePosition(); |
5810 | 0 | const nsStyleCoord* inlineStyleCoord = &stylePos->ISize(aWM); |
5811 | 0 | const nsStyleCoord* blockStyleCoord = &stylePos->BSize(aWM); |
5812 | 0 | auto* parentFrame = GetParent(); |
5813 | 0 | const bool isGridItem = parentFrame && parentFrame->IsGridContainerFrame() && |
5814 | 0 | !HasAnyStateBits(NS_FRAME_OUT_OF_FLOW); |
5815 | 0 | const bool isFlexItem = parentFrame && parentFrame->IsFlexContainerFrame() && |
5816 | 0 | !parentFrame->HasAnyStateBits(NS_STATE_FLEX_IS_EMULATING_LEGACY_BOX) && |
5817 | 0 | !HasAnyStateBits(NS_FRAME_OUT_OF_FLOW); |
5818 | 0 | // This variable only gets set (and used) if isFlexItem is true. It |
5819 | 0 | // indicates which axis (in this frame's own WM) corresponds to its |
5820 | 0 | // flex container's main axis. |
5821 | 0 | LogicalAxis flexMainAxis = eLogicalAxisInline; // (init to make valgrind happy) |
5822 | 0 | Maybe<nsStyleCoord> imposedMainSizeStyleCoord; |
5823 | 0 |
|
5824 | 0 | // If this is a flex item, and we're measuring its cross size after flexing |
5825 | 0 | // to resolve its main size, then we need to use the resolved main size |
5826 | 0 | // that the container provides to us *instead of* the main-size coordinate |
5827 | 0 | // from our style struct. (Otherwise, we'll be using an irrelevant value in |
5828 | 0 | // the aspect-ratio calculations below.) |
5829 | 0 | if (isFlexItem) { |
5830 | 0 | flexMainAxis = nsFlexContainerFrame::IsItemInlineAxisMainAxis(this) ? |
5831 | 0 | eLogicalAxisInline : eLogicalAxisBlock; |
5832 | 0 |
|
5833 | 0 | // If FlexItemMainSizeOverride frame-property is set, then that means the |
5834 | 0 | // flex container is imposing a main-size on this flex item for it to use |
5835 | 0 | // as its size in the container's main axis. |
5836 | 0 | bool didImposeMainSize; |
5837 | 0 | nscoord imposedMainSize = |
5838 | 0 | GetProperty(nsIFrame::FlexItemMainSizeOverride(), &didImposeMainSize); |
5839 | 0 | if (didImposeMainSize) { |
5840 | 0 | imposedMainSizeStyleCoord.emplace(imposedMainSize, |
5841 | 0 | nsStyleCoord::CoordConstructor); |
5842 | 0 | if (flexMainAxis == eLogicalAxisInline) { |
5843 | 0 | inlineStyleCoord = imposedMainSizeStyleCoord.ptr(); |
5844 | 0 | } else { |
5845 | 0 | blockStyleCoord = imposedMainSizeStyleCoord.ptr(); |
5846 | 0 | } |
5847 | 0 |
|
5848 | 0 | } else { |
5849 | 0 | // Flex items use their "flex-basis" property in place of their main-size |
5850 | 0 | // property (e.g. "width") for sizing purposes, *unless* they have |
5851 | 0 | // "flex-basis:auto", in which case they use their main-size property |
5852 | 0 | // after all. |
5853 | 0 | // NOTE: The logic here should match the similar chunk for updating |
5854 | 0 | // mainAxisCoord in nsFrame::ComputeSize() (aside from using a different |
5855 | 0 | // dummy value in the IsUsedFlexBasisContent() case). |
5856 | 0 | const nsStyleCoord* flexBasis = &(stylePos->mFlexBasis); |
5857 | 0 | auto& mainAxisCoord = (flexMainAxis == eLogicalAxisInline |
5858 | 0 | ? inlineStyleCoord : blockStyleCoord); |
5859 | 0 |
|
5860 | 0 | if (nsFlexContainerFrame::IsUsedFlexBasisContent(flexBasis, |
5861 | 0 | mainAxisCoord)) { |
5862 | 0 | // If we get here, we're resolving the flex base size for a flex item, |
5863 | 0 | // and we fall into the flexbox spec section 9.2 step 3, substep C (if |
5864 | 0 | // we have a definite cross size) or E (if not). And specifically: |
5865 | 0 | // |
5866 | 0 | // * If we have a definite cross size, we're supposed to resolve our |
5867 | 0 | // main-size based on that and our intrinsic ratio. |
5868 | 0 | // * Otherwise, we're supposed to produce our max-content size. |
5869 | 0 | // |
5870 | 0 | // Conveniently, we can handle both of those scenarios (regardless of |
5871 | 0 | // which substep we fall into) by using the 'auto' keyword for our |
5872 | 0 | // main-axis coordinate here. (This makes sense, because the spec is |
5873 | 0 | // effectively trying to produce the 'auto' sizing behavior). |
5874 | 0 | static const nsStyleCoord autoStyleCoord(eStyleUnit_Auto); |
5875 | 0 | mainAxisCoord = &autoStyleCoord; |
5876 | 0 | } else if (flexBasis->GetUnit() != eStyleUnit_Auto) { |
5877 | 0 | // For all other non-'auto' flex-basis values, we just swap in the |
5878 | 0 | // flex-basis itself for the main-size property. |
5879 | 0 | mainAxisCoord = flexBasis; |
5880 | 0 | } // else: flex-basis is 'auto', which is deferring to some explicit |
5881 | 0 | // value in mainAxisCoord. So we proceed w/o touching mainAxisCoord. |
5882 | 0 | } |
5883 | 0 | } |
5884 | 0 |
|
5885 | 0 | // Handle intrinsic sizes and their interaction with |
5886 | 0 | // {min-,max-,}{width,height} according to the rules in |
5887 | 0 | // http://www.w3.org/TR/CSS21/visudet.html#min-max-widths |
5888 | 0 |
|
5889 | 0 | // Note: throughout the following section of the function, I avoid |
5890 | 0 | // a * (b / c) because of its reduced accuracy relative to a * b / c |
5891 | 0 | // or (a * b) / c (which are equivalent). |
5892 | 0 |
|
5893 | 0 | const bool isAutoISize = inlineStyleCoord->GetUnit() == eStyleUnit_Auto; |
5894 | 0 | const bool isAutoBSize = |
5895 | 0 | nsLayoutUtils::IsAutoBSize(*blockStyleCoord, aCBSize.BSize(aWM)); |
5896 | 0 |
|
5897 | 0 | LogicalSize boxSizingAdjust(aWM); |
5898 | 0 | if (stylePos->mBoxSizing == StyleBoxSizing::Border) { |
5899 | 0 | boxSizingAdjust = aBorder + aPadding; |
5900 | 0 | } |
5901 | 0 | nscoord boxSizingToMarginEdgeISize = |
5902 | 0 | aMargin.ISize(aWM) + aBorder.ISize(aWM) + aPadding.ISize(aWM) - |
5903 | 0 | boxSizingAdjust.ISize(aWM); |
5904 | 0 |
|
5905 | 0 | nscoord iSize, minISize, maxISize, bSize, minBSize, maxBSize; |
5906 | 0 | enum class Stretch { |
5907 | 0 | // stretch to fill the CB (preserving intrinsic ratio) in the relevant axis |
5908 | 0 | eStretchPreservingRatio, // XXX not used yet |
5909 | 0 | // stretch to fill the CB in the relevant axis |
5910 | 0 | eStretch, |
5911 | 0 | // no stretching in the relevant axis |
5912 | 0 | eNoStretch, |
5913 | 0 | }; |
5914 | 0 | // just to avoid having to type these out everywhere: |
5915 | 0 | const auto eStretchPreservingRatio = Stretch::eStretchPreservingRatio; |
5916 | 0 | const auto eStretch = Stretch::eStretch; |
5917 | 0 | const auto eNoStretch = Stretch::eNoStretch; |
5918 | 0 |
|
5919 | 0 | Stretch stretchI = eNoStretch; // stretch behavior in the inline axis |
5920 | 0 | Stretch stretchB = eNoStretch; // stretch behavior in the block axis |
5921 | 0 |
|
5922 | 0 | const bool isVertical = aWM.IsVertical(); |
5923 | 0 | const nsStyleCoord& isizeCoord = |
5924 | 0 | isVertical ? aIntrinsicSize.height : aIntrinsicSize.width; |
5925 | 0 | const bool hasIntrinsicISize = isizeCoord.GetUnit() == eStyleUnit_Coord; |
5926 | 0 | nscoord intrinsicISize; |
5927 | 0 | if (hasIntrinsicISize) { |
5928 | 0 | intrinsicISize = std::max(nscoord(0), isizeCoord.GetCoordValue()); |
5929 | 0 | } else { |
5930 | 0 | NS_ASSERTION(isizeCoord.GetUnit() == eStyleUnit_None, |
5931 | 0 | "unexpected unit"); |
5932 | 0 | intrinsicISize = 0; |
5933 | 0 | } |
5934 | 0 |
|
5935 | 0 | const nsStyleCoord& bsizeCoord = |
5936 | 0 | isVertical ? aIntrinsicSize.width : aIntrinsicSize.height; |
5937 | 0 | const bool hasIntrinsicBSize = bsizeCoord.GetUnit() == eStyleUnit_Coord; |
5938 | 0 | nscoord intrinsicBSize; |
5939 | 0 | if (hasIntrinsicBSize) { |
5940 | 0 | intrinsicBSize = std::max(nscoord(0), bsizeCoord.GetCoordValue()); |
5941 | 0 | } else { |
5942 | 0 | NS_ASSERTION(bsizeCoord.GetUnit() == eStyleUnit_None, |
5943 | 0 | "unexpected unit"); |
5944 | 0 | intrinsicBSize = 0; |
5945 | 0 | } |
5946 | 0 |
|
5947 | 0 | NS_ASSERTION(aIntrinsicRatio.width >= 0 && aIntrinsicRatio.height >= 0, |
5948 | 0 | "Intrinsic ratio has a negative component!"); |
5949 | 0 | LogicalSize logicalRatio(aWM, aIntrinsicRatio); |
5950 | 0 |
|
5951 | 0 | if (!isAutoISize) { |
5952 | 0 | iSize = ComputeISizeValue(aRenderingContext, |
5953 | 0 | aCBSize.ISize(aWM), boxSizingAdjust.ISize(aWM), |
5954 | 0 | boxSizingToMarginEdgeISize, *inlineStyleCoord, aFlags); |
5955 | 0 | } else if (MOZ_UNLIKELY(isGridItem)) { |
5956 | 0 | MOZ_ASSERT(!IS_TRUE_OVERFLOW_CONTAINER(this)); |
5957 | 0 | // 'auto' inline-size for grid-level box - apply 'stretch' as needed: |
5958 | 0 | auto cbSize = aCBSize.ISize(aWM); |
5959 | 0 | if (cbSize != NS_UNCONSTRAINEDSIZE) { |
5960 | 0 | if (!StyleMargin()->HasInlineAxisAuto(aWM)) { |
5961 | 0 | auto inlineAxisAlignment = |
5962 | 0 | aWM.IsOrthogonalTo(GetParent()->GetWritingMode()) ? |
5963 | 0 | stylePos->UsedAlignSelf(GetParent()->Style()) : |
5964 | 0 | stylePos->UsedJustifySelf(GetParent()->Style()); |
5965 | 0 | // Note: 'normal' means 'start' for elements with an intrinsic size |
5966 | 0 | // or ratio in the relevant dimension, otherwise 'stretch'. |
5967 | 0 | // https://drafts.csswg.org/css-grid/#grid-item-sizing |
5968 | 0 | if ((inlineAxisAlignment == NS_STYLE_ALIGN_NORMAL && |
5969 | 0 | !hasIntrinsicISize && |
5970 | 0 | !(logicalRatio.ISize(aWM) > 0)) || |
5971 | 0 | inlineAxisAlignment == NS_STYLE_ALIGN_STRETCH) { |
5972 | 0 | stretchI = eStretch; |
5973 | 0 | } |
5974 | 0 | } |
5975 | 0 | if (stretchI != eNoStretch || |
5976 | 0 | (aFlags & ComputeSizeFlags::eIClampMarginBoxMinSize)) { |
5977 | 0 | iSize = std::max(nscoord(0), cbSize - |
5978 | 0 | aPadding.ISize(aWM) - |
5979 | 0 | aBorder.ISize(aWM) - |
5980 | 0 | aMargin.ISize(aWM)); |
5981 | 0 | } |
5982 | 0 | } else { |
5983 | 0 | // Reset this flag to avoid applying the clamping below. |
5984 | 0 | aFlags = ComputeSizeFlags(aFlags & |
5985 | 0 | ~ComputeSizeFlags::eIClampMarginBoxMinSize); |
5986 | 0 | } |
5987 | 0 | } |
5988 | 0 |
|
5989 | 0 | const nsStyleCoord& maxISizeCoord = stylePos->MaxISize(aWM); |
5990 | 0 |
|
5991 | 0 | if (maxISizeCoord.GetUnit() != eStyleUnit_None && |
5992 | 0 | !(isFlexItem && flexMainAxis == eLogicalAxisInline)) { |
5993 | 0 | maxISize = ComputeISizeValue(aRenderingContext, |
5994 | 0 | aCBSize.ISize(aWM), boxSizingAdjust.ISize(aWM), |
5995 | 0 | boxSizingToMarginEdgeISize, maxISizeCoord, aFlags); |
5996 | 0 | } else { |
5997 | 0 | maxISize = nscoord_MAX; |
5998 | 0 | } |
5999 | 0 |
|
6000 | 0 | // NOTE: Flex items ignore their min & max sizing properties in their |
6001 | 0 | // flex container's main-axis. (Those properties get applied later in |
6002 | 0 | // the flexbox algorithm.) |
6003 | 0 |
|
6004 | 0 | const nsStyleCoord& minISizeCoord = stylePos->MinISize(aWM); |
6005 | 0 |
|
6006 | 0 | if (minISizeCoord.GetUnit() != eStyleUnit_Auto && |
6007 | 0 | !(isFlexItem && flexMainAxis == eLogicalAxisInline)) { |
6008 | 0 | minISize = ComputeISizeValue(aRenderingContext, |
6009 | 0 | aCBSize.ISize(aWM), boxSizingAdjust.ISize(aWM), |
6010 | 0 | boxSizingToMarginEdgeISize, minISizeCoord, aFlags); |
6011 | 0 | } else { |
6012 | 0 | // Treat "min-width: auto" as 0. |
6013 | 0 | // NOTE: Technically, "auto" is supposed to behave like "min-content" on |
6014 | 0 | // flex items. However, we don't need to worry about that here, because |
6015 | 0 | // flex items' min-sizes are intentionally ignored until the flex |
6016 | 0 | // container explicitly considers them during space distribution. |
6017 | 0 | minISize = 0; |
6018 | 0 | } |
6019 | 0 |
|
6020 | 0 | if (!isAutoBSize) { |
6021 | 0 | bSize = nsLayoutUtils::ComputeBSizeValue(aCBSize.BSize(aWM), |
6022 | 0 | boxSizingAdjust.BSize(aWM), |
6023 | 0 | *blockStyleCoord); |
6024 | 0 | } else if (MOZ_UNLIKELY(isGridItem)) { |
6025 | 0 | MOZ_ASSERT(!IS_TRUE_OVERFLOW_CONTAINER(this)); |
6026 | 0 | // 'auto' block-size for grid-level box - apply 'stretch' as needed: |
6027 | 0 | auto cbSize = aCBSize.BSize(aWM); |
6028 | 0 | if (cbSize != NS_AUTOHEIGHT) { |
6029 | 0 | if (!StyleMargin()->HasBlockAxisAuto(aWM)) { |
6030 | 0 | auto blockAxisAlignment = |
6031 | 0 | !aWM.IsOrthogonalTo(GetParent()->GetWritingMode()) ? |
6032 | 0 | stylePos->UsedAlignSelf(GetParent()->Style()) : |
6033 | 0 | stylePos->UsedJustifySelf(GetParent()->Style()); |
6034 | 0 | // Note: 'normal' means 'start' for elements with an intrinsic size |
6035 | 0 | // or ratio in the relevant dimension, otherwise 'stretch'. |
6036 | 0 | // https://drafts.csswg.org/css-grid/#grid-item-sizing |
6037 | 0 | if ((blockAxisAlignment == NS_STYLE_ALIGN_NORMAL && |
6038 | 0 | !hasIntrinsicBSize && |
6039 | 0 | !(logicalRatio.BSize(aWM) > 0)) || |
6040 | 0 | blockAxisAlignment == NS_STYLE_ALIGN_STRETCH) { |
6041 | 0 | stretchB = eStretch; |
6042 | 0 | } |
6043 | 0 | } |
6044 | 0 | if (stretchB != eNoStretch || |
6045 | 0 | (aFlags & ComputeSizeFlags::eBClampMarginBoxMinSize)) { |
6046 | 0 | bSize = std::max(nscoord(0), cbSize - |
6047 | 0 | aPadding.BSize(aWM) - |
6048 | 0 | aBorder.BSize(aWM) - |
6049 | 0 | aMargin.BSize(aWM)); |
6050 | 0 | } |
6051 | 0 | } else { |
6052 | 0 | // Reset this flag to avoid applying the clamping below. |
6053 | 0 | aFlags = ComputeSizeFlags(aFlags & |
6054 | 0 | ~ComputeSizeFlags::eBClampMarginBoxMinSize); |
6055 | 0 | } |
6056 | 0 | } |
6057 | 0 |
|
6058 | 0 | const nsStyleCoord& maxBSizeCoord = stylePos->MaxBSize(aWM); |
6059 | 0 |
|
6060 | 0 | if (!nsLayoutUtils::IsAutoBSize(maxBSizeCoord, aCBSize.BSize(aWM)) && |
6061 | 0 | !(isFlexItem && flexMainAxis == eLogicalAxisBlock)) { |
6062 | 0 | maxBSize = nsLayoutUtils::ComputeBSizeValue(aCBSize.BSize(aWM), |
6063 | 0 | boxSizingAdjust.BSize(aWM), maxBSizeCoord); |
6064 | 0 | } else { |
6065 | 0 | maxBSize = nscoord_MAX; |
6066 | 0 | } |
6067 | 0 |
|
6068 | 0 | const nsStyleCoord& minBSizeCoord = stylePos->MinBSize(aWM); |
6069 | 0 |
|
6070 | 0 | if (!nsLayoutUtils::IsAutoBSize(minBSizeCoord, aCBSize.BSize(aWM)) && |
6071 | 0 | !(isFlexItem && flexMainAxis == eLogicalAxisBlock)) { |
6072 | 0 | minBSize = nsLayoutUtils::ComputeBSizeValue(aCBSize.BSize(aWM), |
6073 | 0 | boxSizingAdjust.BSize(aWM), minBSizeCoord); |
6074 | 0 | } else { |
6075 | 0 | minBSize = 0; |
6076 | 0 | } |
6077 | 0 |
|
6078 | 0 | NS_ASSERTION(aCBSize.ISize(aWM) != NS_UNCONSTRAINEDSIZE, |
6079 | 0 | "Our containing block must not have unconstrained inline-size!"); |
6080 | 0 |
|
6081 | 0 | // Now calculate the used values for iSize and bSize: |
6082 | 0 |
|
6083 | 0 | if (isAutoISize) { |
6084 | 0 | if (isAutoBSize) { |
6085 | 0 |
|
6086 | 0 | // 'auto' iSize, 'auto' bSize |
6087 | 0 |
|
6088 | 0 | // Get tentative values - CSS 2.1 sections 10.3.2 and 10.6.2: |
6089 | 0 |
|
6090 | 0 | nscoord tentISize, tentBSize; |
6091 | 0 |
|
6092 | 0 | if (hasIntrinsicISize) { |
6093 | 0 | tentISize = intrinsicISize; |
6094 | 0 | } else if (hasIntrinsicBSize && logicalRatio.BSize(aWM) > 0) { |
6095 | 0 | tentISize = NSCoordMulDiv(intrinsicBSize, logicalRatio.ISize(aWM), logicalRatio.BSize(aWM)); |
6096 | 0 | } else if (logicalRatio.ISize(aWM) > 0) { |
6097 | 0 | tentISize = aCBSize.ISize(aWM) - boxSizingToMarginEdgeISize; // XXX scrollbar? |
6098 | 0 | if (tentISize < 0) tentISize = 0; |
6099 | 0 | } else { |
6100 | 0 | tentISize = nsPresContext::CSSPixelsToAppUnits(300); |
6101 | 0 | } |
6102 | 0 |
|
6103 | 0 | // If we need to clamp the inline size to fit the CB, we use the 'stretch' |
6104 | 0 | // or 'normal' codepath. We use the ratio-preserving 'normal' codepath |
6105 | 0 | // unless we have 'stretch' in the other axis. |
6106 | 0 | if ((aFlags & ComputeSizeFlags::eIClampMarginBoxMinSize) && |
6107 | 0 | stretchI != eStretch && tentISize > iSize) { |
6108 | 0 | stretchI = (stretchB == eStretch ? eStretch : eStretchPreservingRatio); |
6109 | 0 | } |
6110 | 0 |
|
6111 | 0 | if (hasIntrinsicBSize) { |
6112 | 0 | tentBSize = intrinsicBSize; |
6113 | 0 | } else if (logicalRatio.ISize(aWM) > 0) { |
6114 | 0 | tentBSize = NSCoordMulDiv(tentISize, logicalRatio.BSize(aWM), logicalRatio.ISize(aWM)); |
6115 | 0 | } else { |
6116 | 0 | tentBSize = nsPresContext::CSSPixelsToAppUnits(150); |
6117 | 0 | } |
6118 | 0 |
|
6119 | 0 | // (ditto the comment about clamping the inline size above) |
6120 | 0 | if ((aFlags & ComputeSizeFlags::eBClampMarginBoxMinSize) && |
6121 | 0 | stretchB != eStretch && tentBSize > bSize) { |
6122 | 0 | stretchB = (stretchI == eStretch ? eStretch : eStretchPreservingRatio); |
6123 | 0 | } |
6124 | 0 |
|
6125 | 0 | if (aIntrinsicRatio != nsSize(0, 0)) { |
6126 | 0 | if (stretchI == eStretch) { |
6127 | 0 | tentISize = iSize; // * / 'stretch' |
6128 | 0 | if (stretchB == eStretch) { |
6129 | 0 | tentBSize = bSize; // 'stretch' / 'stretch' |
6130 | 0 | } else if (stretchB == eStretchPreservingRatio && logicalRatio.ISize(aWM) > 0) { |
6131 | 0 | // 'normal' / 'stretch' |
6132 | 0 | tentBSize = NSCoordMulDiv(iSize, logicalRatio.BSize(aWM), logicalRatio.ISize(aWM)); |
6133 | 0 | } |
6134 | 0 | } else if (stretchB == eStretch) { |
6135 | 0 | tentBSize = bSize; // 'stretch' / * (except 'stretch') |
6136 | 0 | if (stretchI == eStretchPreservingRatio && logicalRatio.BSize(aWM) > 0) { |
6137 | 0 | // 'stretch' / 'normal' |
6138 | 0 | tentISize = NSCoordMulDiv(bSize, logicalRatio.ISize(aWM), logicalRatio.BSize(aWM)); |
6139 | 0 | } |
6140 | 0 | } else if (stretchI == eStretchPreservingRatio) { |
6141 | 0 | tentISize = iSize; // * (except 'stretch') / 'normal' |
6142 | 0 | if (logicalRatio.ISize(aWM) > 0) { |
6143 | 0 | tentBSize = NSCoordMulDiv(iSize, logicalRatio.BSize(aWM), logicalRatio.ISize(aWM)); |
6144 | 0 | } |
6145 | 0 | if (stretchB == eStretchPreservingRatio && tentBSize > bSize) { |
6146 | 0 | // Stretch within the CB size with preserved intrinsic ratio. |
6147 | 0 | tentBSize = bSize; // 'normal' / 'normal' |
6148 | 0 | if (logicalRatio.BSize(aWM) > 0) { |
6149 | 0 | tentISize = NSCoordMulDiv(bSize, logicalRatio.ISize(aWM), logicalRatio.BSize(aWM)); |
6150 | 0 | } |
6151 | 0 | } |
6152 | 0 | } else if (stretchB == eStretchPreservingRatio) { |
6153 | 0 | tentBSize = bSize; // 'normal' / * (except 'normal' and 'stretch') |
6154 | 0 | if (logicalRatio.BSize(aWM) > 0) { |
6155 | 0 | tentISize = NSCoordMulDiv(bSize, logicalRatio.ISize(aWM), logicalRatio.BSize(aWM)); |
6156 | 0 | } |
6157 | 0 | } |
6158 | 0 | } |
6159 | 0 |
|
6160 | 0 | // ComputeAutoSizeWithIntrinsicDimensions preserves the ratio when applying |
6161 | 0 | // the min/max-size. We don't want that when we have 'stretch' in either |
6162 | 0 | // axis because tentISize/tentBSize is likely not according to ratio now. |
6163 | 0 | if (aIntrinsicRatio != nsSize(0, 0) && |
6164 | 0 | stretchI != eStretch && stretchB != eStretch) { |
6165 | 0 | nsSize autoSize = nsLayoutUtils:: |
6166 | 0 | ComputeAutoSizeWithIntrinsicDimensions(minISize, minBSize, |
6167 | 0 | maxISize, maxBSize, |
6168 | 0 | tentISize, tentBSize); |
6169 | 0 | // The nsSize that ComputeAutoSizeWithIntrinsicDimensions returns will |
6170 | 0 | // actually contain logical values if the parameters passed to it were |
6171 | 0 | // logical coordinates, so we do NOT perform a physical-to-logical |
6172 | 0 | // conversion here, but just assign the fields directly to our result. |
6173 | 0 | iSize = autoSize.width; |
6174 | 0 | bSize = autoSize.height; |
6175 | 0 | } else { |
6176 | 0 | // Not honoring an intrinsic ratio: clamp the dimensions independently. |
6177 | 0 | iSize = NS_CSS_MINMAX(tentISize, minISize, maxISize); |
6178 | 0 | bSize = NS_CSS_MINMAX(tentBSize, minBSize, maxBSize); |
6179 | 0 | } |
6180 | 0 | } else { |
6181 | 0 |
|
6182 | 0 | // 'auto' iSize, non-'auto' bSize |
6183 | 0 | bSize = NS_CSS_MINMAX(bSize, minBSize, maxBSize); |
6184 | 0 | if (stretchI != eStretch) { |
6185 | 0 | if (logicalRatio.BSize(aWM) > 0) { |
6186 | 0 | iSize = NSCoordMulDiv(bSize, logicalRatio.ISize(aWM), logicalRatio.BSize(aWM)); |
6187 | 0 | } else if (hasIntrinsicISize) { |
6188 | 0 | if (!((aFlags & ComputeSizeFlags::eIClampMarginBoxMinSize) && |
6189 | 0 | intrinsicISize > iSize)) { |
6190 | 0 | iSize = intrinsicISize; |
6191 | 0 | } // else - leave iSize as is to fill the CB |
6192 | 0 | } else { |
6193 | 0 | iSize = nsPresContext::CSSPixelsToAppUnits(300); |
6194 | 0 | } |
6195 | 0 | } // else - leave iSize as is to fill the CB |
6196 | 0 | iSize = NS_CSS_MINMAX(iSize, minISize, maxISize); |
6197 | 0 |
|
6198 | 0 | } |
6199 | 0 | } else { |
6200 | 0 | if (isAutoBSize) { |
6201 | 0 |
|
6202 | 0 | // non-'auto' iSize, 'auto' bSize |
6203 | 0 | iSize = NS_CSS_MINMAX(iSize, minISize, maxISize); |
6204 | 0 | if (stretchB != eStretch) { |
6205 | 0 | if (logicalRatio.ISize(aWM) > 0) { |
6206 | 0 | bSize = NSCoordMulDiv(iSize, logicalRatio.BSize(aWM), logicalRatio.ISize(aWM)); |
6207 | 0 | } else if (hasIntrinsicBSize) { |
6208 | 0 | if (!((aFlags & ComputeSizeFlags::eBClampMarginBoxMinSize) && |
6209 | 0 | intrinsicBSize > bSize)) { |
6210 | 0 | bSize = intrinsicBSize; |
6211 | 0 | } // else - leave bSize as is to fill the CB |
6212 | 0 | } else { |
6213 | 0 | bSize = nsPresContext::CSSPixelsToAppUnits(150); |
6214 | 0 | } |
6215 | 0 | } // else - leave bSize as is to fill the CB |
6216 | 0 | bSize = NS_CSS_MINMAX(bSize, minBSize, maxBSize); |
6217 | 0 |
|
6218 | 0 | } else { |
6219 | 0 |
|
6220 | 0 | // non-'auto' iSize, non-'auto' bSize |
6221 | 0 | iSize = NS_CSS_MINMAX(iSize, minISize, maxISize); |
6222 | 0 | bSize = NS_CSS_MINMAX(bSize, minBSize, maxBSize); |
6223 | 0 |
|
6224 | 0 | } |
6225 | 0 | } |
6226 | 0 |
|
6227 | 0 | return LogicalSize(aWM, iSize, bSize); |
6228 | 0 | } |
6229 | | |
6230 | | nsRect |
6231 | | nsIFrame::ComputeTightBounds(DrawTarget* aDrawTarget) const |
6232 | 0 | { |
6233 | 0 | return GetVisualOverflowRect(); |
6234 | 0 | } |
6235 | | |
6236 | | nsRect |
6237 | | nsFrame::ComputeSimpleTightBounds(DrawTarget* aDrawTarget) const |
6238 | 0 | { |
6239 | 0 | if (StyleOutline()->ShouldPaintOutline() || StyleBorder()->HasBorder() || |
6240 | 0 | !StyleBackground()->IsTransparent(this) || |
6241 | 0 | StyleDisplay()->HasAppearance()) { |
6242 | 0 | // Not necessarily tight, due to clipping, negative |
6243 | 0 | // outline-offset, and lots of other issues, but that's OK |
6244 | 0 | return GetVisualOverflowRect(); |
6245 | 0 | } |
6246 | 0 | |
6247 | 0 | nsRect r(0, 0, 0, 0); |
6248 | 0 | ChildListIterator lists(this); |
6249 | 0 | for (; !lists.IsDone(); lists.Next()) { |
6250 | 0 | nsFrameList::Enumerator childFrames(lists.CurrentList()); |
6251 | 0 | for (; !childFrames.AtEnd(); childFrames.Next()) { |
6252 | 0 | nsIFrame* child = childFrames.get(); |
6253 | 0 | r.UnionRect(r, child->ComputeTightBounds(aDrawTarget) + child->GetPosition()); |
6254 | 0 | } |
6255 | 0 | } |
6256 | 0 | return r; |
6257 | 0 | } |
6258 | | |
6259 | | /* virtual */ nsresult |
6260 | | nsIFrame::GetPrefWidthTightBounds(gfxContext* aContext, |
6261 | | nscoord* aX, |
6262 | | nscoord* aXMost) |
6263 | 0 | { |
6264 | 0 | return NS_ERROR_NOT_IMPLEMENTED; |
6265 | 0 | } |
6266 | | |
6267 | | /* virtual */ |
6268 | | LogicalSize |
6269 | | nsFrame::ComputeAutoSize(gfxContext* aRenderingContext, |
6270 | | WritingMode aWM, |
6271 | | const mozilla::LogicalSize& aCBSize, |
6272 | | nscoord aAvailableISize, |
6273 | | const mozilla::LogicalSize& aMargin, |
6274 | | const mozilla::LogicalSize& aBorder, |
6275 | | const mozilla::LogicalSize& aPadding, |
6276 | | ComputeSizeFlags aFlags) |
6277 | 0 | { |
6278 | 0 | // Use basic shrink-wrapping as a default implementation. |
6279 | 0 | LogicalSize result(aWM, 0xdeadbeef, NS_UNCONSTRAINEDSIZE); |
6280 | 0 |
|
6281 | 0 | // don't bother setting it if the result won't be used |
6282 | 0 | if (StylePosition()->ISize(aWM).GetUnit() == eStyleUnit_Auto) { |
6283 | 0 | nscoord availBased = aAvailableISize - aMargin.ISize(aWM) - |
6284 | 0 | aBorder.ISize(aWM) - aPadding.ISize(aWM); |
6285 | 0 | result.ISize(aWM) = ShrinkWidthToFit(aRenderingContext, availBased, aFlags); |
6286 | 0 | } |
6287 | 0 | return result; |
6288 | 0 | } |
6289 | | |
6290 | | nscoord |
6291 | | nsFrame::ShrinkWidthToFit(gfxContext* aRenderingContext, |
6292 | | nscoord aISizeInCB, |
6293 | | ComputeSizeFlags aFlags) |
6294 | 0 | { |
6295 | 0 | // If we're a container for font size inflation, then shrink |
6296 | 0 | // wrapping inside of us should not apply font size inflation. |
6297 | 0 | AutoMaybeDisableFontInflation an(this); |
6298 | 0 |
|
6299 | 0 | nscoord result; |
6300 | 0 | nscoord minISize = GetMinISize(aRenderingContext); |
6301 | 0 | if (minISize > aISizeInCB) { |
6302 | 0 | const bool clamp = aFlags & ComputeSizeFlags::eIClampMarginBoxMinSize; |
6303 | 0 | result = MOZ_UNLIKELY(clamp) ? aISizeInCB : minISize; |
6304 | 0 | } else { |
6305 | 0 | nscoord prefISize = GetPrefISize(aRenderingContext); |
6306 | 0 | if (prefISize > aISizeInCB) { |
6307 | 0 | result = aISizeInCB; |
6308 | 0 | } else { |
6309 | 0 | result = prefISize; |
6310 | 0 | } |
6311 | 0 | } |
6312 | 0 | return result; |
6313 | 0 | } |
6314 | | |
6315 | | nscoord |
6316 | | nsIFrame::ComputeISizeValue(gfxContext* aRenderingContext, |
6317 | | nscoord aContainingBlockISize, |
6318 | | nscoord aContentEdgeToBoxSizing, |
6319 | | nscoord aBoxSizingToMarginEdge, |
6320 | | const nsStyleCoord& aCoord, |
6321 | | ComputeSizeFlags aFlags) |
6322 | 0 | { |
6323 | 0 | MOZ_ASSERT(aRenderingContext, "non-null rendering context expected"); |
6324 | 0 | LAYOUT_WARN_IF_FALSE(aContainingBlockISize != NS_UNCONSTRAINEDSIZE, |
6325 | 0 | "have unconstrained inline-size; this should only result from " |
6326 | 0 | "very large sizes, not attempts at intrinsic inline-size " |
6327 | 0 | "calculation"); |
6328 | 0 | MOZ_ASSERT(aContainingBlockISize >= 0, |
6329 | 0 | "inline-size less than zero"); |
6330 | 0 |
|
6331 | 0 | nscoord result; |
6332 | 0 | if (aCoord.IsCoordPercentCalcUnit()) { |
6333 | 0 | result = aCoord.ComputeCoordPercentCalc(aContainingBlockISize); |
6334 | 0 | // The result of a calc() expression might be less than 0; we |
6335 | 0 | // should clamp at runtime (below). (Percentages and coords that |
6336 | 0 | // are less than 0 have already been dropped by the parser.) |
6337 | 0 | result -= aContentEdgeToBoxSizing; |
6338 | 0 | } else { |
6339 | 0 | MOZ_ASSERT(eStyleUnit_Enumerated == aCoord.GetUnit()); |
6340 | 0 | // If 'this' is a container for font size inflation, then shrink |
6341 | 0 | // wrapping inside of it should not apply font size inflation. |
6342 | 0 | AutoMaybeDisableFontInflation an(this); |
6343 | 0 |
|
6344 | 0 | int32_t val = aCoord.GetIntValue(); |
6345 | 0 | switch (val) { |
6346 | 0 | case NS_STYLE_WIDTH_MAX_CONTENT: |
6347 | 0 | result = GetPrefISize(aRenderingContext); |
6348 | 0 | NS_ASSERTION(result >= 0, "inline-size less than zero"); |
6349 | 0 | break; |
6350 | 0 | case NS_STYLE_WIDTH_MIN_CONTENT: |
6351 | 0 | result = GetMinISize(aRenderingContext); |
6352 | 0 | NS_ASSERTION(result >= 0, "inline-size less than zero"); |
6353 | 0 | if (MOZ_UNLIKELY(aFlags & ComputeSizeFlags::eIClampMarginBoxMinSize)) { |
6354 | 0 | auto available = aContainingBlockISize - |
6355 | 0 | (aBoxSizingToMarginEdge + aContentEdgeToBoxSizing); |
6356 | 0 | result = std::min(available, result); |
6357 | 0 | } |
6358 | 0 | break; |
6359 | 0 | case NS_STYLE_WIDTH_FIT_CONTENT: |
6360 | 0 | { |
6361 | 0 | nscoord pref = GetPrefISize(aRenderingContext), |
6362 | 0 | min = GetMinISize(aRenderingContext), |
6363 | 0 | fill = aContainingBlockISize - |
6364 | 0 | (aBoxSizingToMarginEdge + aContentEdgeToBoxSizing); |
6365 | 0 | if (MOZ_UNLIKELY(aFlags & ComputeSizeFlags::eIClampMarginBoxMinSize)) { |
6366 | 0 | min = std::min(min, fill); |
6367 | 0 | } |
6368 | 0 | result = std::max(min, std::min(pref, fill)); |
6369 | 0 | NS_ASSERTION(result >= 0, "inline-size less than zero"); |
6370 | 0 | } |
6371 | 0 | break; |
6372 | 0 | case NS_STYLE_WIDTH_AVAILABLE: |
6373 | 0 | result = aContainingBlockISize - |
6374 | 0 | (aBoxSizingToMarginEdge + aContentEdgeToBoxSizing); |
6375 | 0 | } |
6376 | 0 | } |
6377 | 0 |
|
6378 | 0 | return std::max(0, result); |
6379 | 0 | } |
6380 | | |
6381 | | void |
6382 | | nsFrame::DidReflow(nsPresContext* aPresContext, |
6383 | | const ReflowInput* aReflowInput) |
6384 | 0 | { |
6385 | 0 | NS_FRAME_TRACE_MSG(NS_FRAME_TRACE_CALLS, ("nsFrame::DidReflow")); |
6386 | 0 |
|
6387 | 0 | SVGObserverUtils::InvalidateDirectRenderingObservers(this, |
6388 | 0 | SVGObserverUtils::INVALIDATE_REFLOW); |
6389 | 0 |
|
6390 | 0 | RemoveStateBits(NS_FRAME_IN_REFLOW | NS_FRAME_FIRST_REFLOW | |
6391 | 0 | NS_FRAME_IS_DIRTY | NS_FRAME_HAS_DIRTY_CHILDREN); |
6392 | 0 |
|
6393 | 0 | // Notify the percent bsize observer if there is a percent bsize. |
6394 | 0 | // The observer may be able to initiate another reflow with a computed |
6395 | 0 | // bsize. This happens in the case where a table cell has no computed |
6396 | 0 | // bsize but can fabricate one when the cell bsize is known. |
6397 | 0 | if (aReflowInput && aReflowInput->mPercentBSizeObserver && |
6398 | 0 | !GetPrevInFlow()) { |
6399 | 0 | const nsStyleCoord &bsize = |
6400 | 0 | aReflowInput->mStylePosition->BSize(aReflowInput->GetWritingMode()); |
6401 | 0 | if (bsize.HasPercent()) { |
6402 | 0 | aReflowInput->mPercentBSizeObserver->NotifyPercentBSize(*aReflowInput); |
6403 | 0 | } |
6404 | 0 | } |
6405 | 0 |
|
6406 | 0 | aPresContext->ReflowedFrame(); |
6407 | 0 | } |
6408 | | |
6409 | | void |
6410 | | nsFrame::FinishReflowWithAbsoluteFrames(nsPresContext* aPresContext, |
6411 | | ReflowOutput& aDesiredSize, |
6412 | | const ReflowInput& aReflowInput, |
6413 | | nsReflowStatus& aStatus, |
6414 | | bool aConstrainBSize) |
6415 | 0 | { |
6416 | 0 | ReflowAbsoluteFrames(aPresContext, aDesiredSize, aReflowInput, aStatus, aConstrainBSize); |
6417 | 0 |
|
6418 | 0 | FinishAndStoreOverflow(&aDesiredSize, aReflowInput.mStyleDisplay); |
6419 | 0 | } |
6420 | | |
6421 | | void |
6422 | | nsFrame::ReflowAbsoluteFrames(nsPresContext* aPresContext, |
6423 | | ReflowOutput& aDesiredSize, |
6424 | | const ReflowInput& aReflowInput, |
6425 | | nsReflowStatus& aStatus, |
6426 | | bool aConstrainBSize) |
6427 | 0 | { |
6428 | 0 | if (HasAbsolutelyPositionedChildren()) { |
6429 | 0 | nsAbsoluteContainingBlock* absoluteContainer = GetAbsoluteContainingBlock(); |
6430 | 0 |
|
6431 | 0 | // Let the absolutely positioned container reflow any absolutely positioned |
6432 | 0 | // child frames that need to be reflowed |
6433 | 0 |
|
6434 | 0 | // The containing block for the abs pos kids is formed by our padding edge. |
6435 | 0 | nsMargin usedBorder = GetUsedBorder(); |
6436 | 0 | nscoord containingBlockWidth = |
6437 | 0 | std::max(0, aDesiredSize.Width() - usedBorder.LeftRight()); |
6438 | 0 | nscoord containingBlockHeight = |
6439 | 0 | std::max(0, aDesiredSize.Height() - usedBorder.TopBottom()); |
6440 | 0 | nsContainerFrame* container = do_QueryFrame(this); |
6441 | 0 | NS_ASSERTION(container, "Abs-pos children only supported on container frames for now"); |
6442 | 0 |
|
6443 | 0 | nsRect containingBlock(0, 0, containingBlockWidth, containingBlockHeight); |
6444 | 0 | AbsPosReflowFlags flags = |
6445 | 0 | AbsPosReflowFlags::eCBWidthAndHeightChanged; // XXX could be optimized |
6446 | 0 | if (aConstrainBSize) { |
6447 | 0 | flags |= AbsPosReflowFlags::eConstrainHeight; |
6448 | 0 | } |
6449 | 0 | absoluteContainer->Reflow(container, aPresContext, aReflowInput, aStatus, |
6450 | 0 | containingBlock, flags, |
6451 | 0 | &aDesiredSize.mOverflowAreas); |
6452 | 0 | } |
6453 | 0 | } |
6454 | | |
6455 | | void |
6456 | | nsFrame::PushDirtyBitToAbsoluteFrames() |
6457 | 0 | { |
6458 | 0 | if (!(GetStateBits() & NS_FRAME_IS_DIRTY)) { |
6459 | 0 | return; // No dirty bit to push. |
6460 | 0 | } |
6461 | 0 | if (!HasAbsolutelyPositionedChildren()) { |
6462 | 0 | return; // No absolute children to push to. |
6463 | 0 | } |
6464 | 0 | GetAbsoluteContainingBlock()->MarkAllFramesDirty(); |
6465 | 0 | } |
6466 | | |
6467 | | /* virtual */ bool |
6468 | | nsFrame::CanContinueTextRun() const |
6469 | 0 | { |
6470 | 0 | // By default, a frame will *not* allow a text run to be continued |
6471 | 0 | // through it. |
6472 | 0 | return false; |
6473 | 0 | } |
6474 | | |
6475 | | void |
6476 | | nsFrame::Reflow(nsPresContext* aPresContext, |
6477 | | ReflowOutput& aDesiredSize, |
6478 | | const ReflowInput& aReflowInput, |
6479 | | nsReflowStatus& aStatus) |
6480 | 0 | { |
6481 | 0 | MarkInReflow(); |
6482 | 0 | DO_GLOBAL_REFLOW_COUNT("nsFrame"); |
6483 | 0 | MOZ_ASSERT(aStatus.IsEmpty(), "Caller should pass a fresh reflow status!"); |
6484 | 0 | aDesiredSize.ClearSize(); |
6485 | 0 | NS_FRAME_SET_TRUNCATION(aStatus, aReflowInput, aDesiredSize); |
6486 | 0 | } |
6487 | | |
6488 | | bool |
6489 | | nsIFrame::IsContentDisabled() const |
6490 | 0 | { |
6491 | 0 | // FIXME(emilio): Doing this via CSS means callers must ensure the style is up |
6492 | 0 | // to date, and they don't! |
6493 | 0 | if (StyleUI()->mUserInput == StyleUserInput::None) { |
6494 | 0 | return true; |
6495 | 0 | } |
6496 | 0 | |
6497 | 0 | auto* element = nsGenericHTMLElement::FromNodeOrNull(GetContent()); |
6498 | 0 | return element && element->IsDisabled(); |
6499 | 0 | } |
6500 | | |
6501 | | nsresult |
6502 | | nsFrame::CharacterDataChanged(const CharacterDataChangeInfo&) |
6503 | 0 | { |
6504 | 0 | MOZ_ASSERT_UNREACHABLE("should only be called for text frames"); |
6505 | 0 | return NS_OK; |
6506 | 0 | } |
6507 | | |
6508 | | nsresult |
6509 | | nsFrame::AttributeChanged(int32_t aNameSpaceID, |
6510 | | nsAtom* aAttribute, |
6511 | | int32_t aModType) |
6512 | 0 | { |
6513 | 0 | return NS_OK; |
6514 | 0 | } |
6515 | | |
6516 | | // Flow member functions |
6517 | | |
6518 | | nsSplittableType |
6519 | | nsFrame::GetSplittableType() const |
6520 | 0 | { |
6521 | 0 | return NS_FRAME_NOT_SPLITTABLE; |
6522 | 0 | } |
6523 | | |
6524 | | nsIFrame* nsFrame::GetPrevContinuation() const |
6525 | 0 | { |
6526 | 0 | return nullptr; |
6527 | 0 | } |
6528 | | |
6529 | | void |
6530 | | nsFrame::SetPrevContinuation(nsIFrame* aPrevContinuation) |
6531 | 0 | { |
6532 | 0 | MOZ_ASSERT(false, "not splittable"); |
6533 | 0 | } |
6534 | | |
6535 | | nsIFrame* nsFrame::GetNextContinuation() const |
6536 | 0 | { |
6537 | 0 | return nullptr; |
6538 | 0 | } |
6539 | | |
6540 | | void |
6541 | | nsFrame::SetNextContinuation(nsIFrame*) |
6542 | 0 | { |
6543 | 0 | MOZ_ASSERT(false, "not splittable"); |
6544 | 0 | } |
6545 | | |
6546 | | nsIFrame* nsFrame::GetPrevInFlowVirtual() const |
6547 | 0 | { |
6548 | 0 | return nullptr; |
6549 | 0 | } |
6550 | | |
6551 | | void |
6552 | | nsFrame::SetPrevInFlow(nsIFrame* aPrevInFlow) |
6553 | 0 | { |
6554 | 0 | MOZ_ASSERT(false, "not splittable"); |
6555 | 0 | } |
6556 | | |
6557 | | nsIFrame* nsFrame::GetNextInFlowVirtual() const |
6558 | 0 | { |
6559 | 0 | return nullptr; |
6560 | 0 | } |
6561 | | |
6562 | | void |
6563 | | nsFrame::SetNextInFlow(nsIFrame*) |
6564 | 0 | { |
6565 | 0 | MOZ_ASSERT(false, "not splittable"); |
6566 | 0 | } |
6567 | | |
6568 | | nsIFrame* nsIFrame::GetTailContinuation() |
6569 | 0 | { |
6570 | 0 | nsIFrame* frame = this; |
6571 | 0 | while (frame->GetStateBits() & NS_FRAME_IS_OVERFLOW_CONTAINER) { |
6572 | 0 | frame = frame->GetPrevContinuation(); |
6573 | 0 | NS_ASSERTION(frame, "first continuation can't be overflow container"); |
6574 | 0 | } |
6575 | 0 | for (nsIFrame* next = frame->GetNextContinuation(); |
6576 | 0 | next && !(next->GetStateBits() & NS_FRAME_IS_OVERFLOW_CONTAINER); |
6577 | 0 | next = frame->GetNextContinuation()) { |
6578 | 0 | frame = next; |
6579 | 0 | } |
6580 | 0 |
|
6581 | 0 | MOZ_ASSERT(frame, "illegal state in continuation chain."); |
6582 | 0 | return frame; |
6583 | 0 | } |
6584 | | |
6585 | | // Associated view object |
6586 | | void |
6587 | | nsIFrame::SetView(nsView* aView) |
6588 | 0 | { |
6589 | 0 | if (aView) { |
6590 | 0 | aView->SetFrame(this); |
6591 | 0 |
|
6592 | | #ifdef DEBUG |
6593 | | LayoutFrameType frameType = Type(); |
6594 | | NS_ASSERTION(frameType == LayoutFrameType::SubDocument || |
6595 | | frameType == LayoutFrameType::ListControl || |
6596 | | frameType == LayoutFrameType::Object || |
6597 | | frameType == LayoutFrameType::Viewport || |
6598 | | frameType == LayoutFrameType::MenuPopup, |
6599 | | "Only specific frame types can have an nsView"); |
6600 | | #endif |
6601 | |
|
6602 | 0 | // Store the view on the frame. |
6603 | 0 | SetViewInternal(aView); |
6604 | 0 |
|
6605 | 0 | // Set the frame state bit that says the frame has a view |
6606 | 0 | AddStateBits(NS_FRAME_HAS_VIEW); |
6607 | 0 |
|
6608 | 0 | // Let all of the ancestors know they have a descendant with a view. |
6609 | 0 | for (nsIFrame* f = GetParent(); |
6610 | 0 | f && !(f->GetStateBits() & NS_FRAME_HAS_CHILD_WITH_VIEW); |
6611 | 0 | f = f->GetParent()) |
6612 | 0 | f->AddStateBits(NS_FRAME_HAS_CHILD_WITH_VIEW); |
6613 | 0 | } else { |
6614 | 0 | MOZ_ASSERT_UNREACHABLE("Destroying a view while the frame is alive?"); |
6615 | 0 | RemoveStateBits(NS_FRAME_HAS_VIEW); |
6616 | 0 | SetViewInternal(nullptr); |
6617 | 0 | } |
6618 | 0 | } |
6619 | | |
6620 | | // Find the first geometric parent that has a view |
6621 | | nsIFrame* nsIFrame::GetAncestorWithView() const |
6622 | 0 | { |
6623 | 0 | for (nsIFrame* f = GetParent(); nullptr != f; f = f->GetParent()) { |
6624 | 0 | if (f->HasView()) { |
6625 | 0 | return f; |
6626 | 0 | } |
6627 | 0 | } |
6628 | 0 | return nullptr; |
6629 | 0 | } |
6630 | | |
6631 | | template<nsPoint (nsIFrame::* PositionGetter)() const> |
6632 | | static nsPoint OffsetCalculator(const nsIFrame* aThis, const nsIFrame* aOther) |
6633 | 0 | { |
6634 | 0 | MOZ_ASSERT(aOther, |
6635 | 0 | "Must have frame for destination coordinate system!"); |
6636 | 0 |
|
6637 | 0 | NS_ASSERTION(aThis->PresContext() == aOther->PresContext(), |
6638 | 0 | "GetOffsetTo called on frames in different documents"); |
6639 | 0 |
|
6640 | 0 | nsPoint offset(0, 0); |
6641 | 0 | const nsIFrame* f; |
6642 | 0 | for (f = aThis; f != aOther && f; f = f->GetParent()) { |
6643 | 0 | offset += (f->*PositionGetter)(); |
6644 | 0 | } |
6645 | 0 |
|
6646 | 0 | if (f != aOther) { |
6647 | 0 | // Looks like aOther wasn't an ancestor of |this|. So now we have |
6648 | 0 | // the root-frame-relative position of |this| in |offset|. Convert back |
6649 | 0 | // to the coordinates of aOther |
6650 | 0 | while (aOther) { |
6651 | 0 | offset -= (aOther->*PositionGetter)(); |
6652 | 0 | aOther = aOther->GetParent(); |
6653 | 0 | } |
6654 | 0 | } |
6655 | 0 |
|
6656 | 0 | return offset; |
6657 | 0 | } Unexecuted instantiation: Unified_cpp_layout_generic1.cpp:nsPoint OffsetCalculator<&(nsIFrame::GetPosition() const)>(nsIFrame const*, nsIFrame const*) Unexecuted instantiation: Unified_cpp_layout_generic1.cpp:nsPoint OffsetCalculator<&(nsIFrame::GetPositionIgnoringScrolling() const)>(nsIFrame const*, nsIFrame const*) |
6658 | | |
6659 | | nsPoint |
6660 | | nsIFrame::GetOffsetTo(const nsIFrame* aOther) const |
6661 | 0 | { |
6662 | 0 | return OffsetCalculator<&nsIFrame::GetPosition>(this, aOther); |
6663 | 0 | } |
6664 | | |
6665 | | nsPoint |
6666 | | nsIFrame::GetOffsetToIgnoringScrolling(const nsIFrame* aOther) const |
6667 | 0 | { |
6668 | 0 | return OffsetCalculator<&nsIFrame::GetPositionIgnoringScrolling>(this, aOther); |
6669 | 0 | } |
6670 | | |
6671 | | nsPoint nsIFrame::GetOffsetToCrossDoc(const nsIFrame* aOther) const |
6672 | 0 | { |
6673 | 0 | return GetOffsetToCrossDoc(aOther, PresContext()->AppUnitsPerDevPixel()); |
6674 | 0 | } |
6675 | | |
6676 | | nsPoint |
6677 | | nsIFrame::GetOffsetToCrossDoc(const nsIFrame* aOther, const int32_t aAPD) const |
6678 | 0 | { |
6679 | 0 | MOZ_ASSERT(aOther, |
6680 | 0 | "Must have frame for destination coordinate system!"); |
6681 | 0 | NS_ASSERTION(PresContext()->GetRootPresContext() == |
6682 | 0 | aOther->PresContext()->GetRootPresContext(), |
6683 | 0 | "trying to get the offset between frames in different document " |
6684 | 0 | "hierarchies?"); |
6685 | 0 | if (PresContext()->GetRootPresContext() != |
6686 | 0 | aOther->PresContext()->GetRootPresContext()) { |
6687 | 0 | // crash right away, we are almost certainly going to crash anyway. |
6688 | 0 | MOZ_CRASH("trying to get the offset between frames in different " |
6689 | 0 | "document hierarchies?"); |
6690 | 0 | } |
6691 | 0 |
|
6692 | 0 | const nsIFrame* root = nullptr; |
6693 | 0 | // offset will hold the final offset |
6694 | 0 | // docOffset holds the currently accumulated offset at the current APD, it |
6695 | 0 | // will be converted and added to offset when the current APD changes. |
6696 | 0 | nsPoint offset(0, 0), docOffset(0, 0); |
6697 | 0 | const nsIFrame* f = this; |
6698 | 0 | int32_t currAPD = PresContext()->AppUnitsPerDevPixel(); |
6699 | 0 | while (f && f != aOther) { |
6700 | 0 | docOffset += f->GetPosition(); |
6701 | 0 | nsIFrame* parent = f->GetParent(); |
6702 | 0 | if (parent) { |
6703 | 0 | f = parent; |
6704 | 0 | } else { |
6705 | 0 | nsPoint newOffset(0, 0); |
6706 | 0 | root = f; |
6707 | 0 | f = nsLayoutUtils::GetCrossDocParentFrame(f, &newOffset); |
6708 | 0 | int32_t newAPD = f ? f->PresContext()->AppUnitsPerDevPixel() : 0; |
6709 | 0 | if (!f || newAPD != currAPD) { |
6710 | 0 | // Convert docOffset to the right APD and add it to offset. |
6711 | 0 | offset += docOffset.ScaleToOtherAppUnits(currAPD, aAPD); |
6712 | 0 | docOffset.x = docOffset.y = 0; |
6713 | 0 | } |
6714 | 0 | currAPD = newAPD; |
6715 | 0 | docOffset += newOffset; |
6716 | 0 | } |
6717 | 0 | } |
6718 | 0 | if (f == aOther) { |
6719 | 0 | offset += docOffset.ScaleToOtherAppUnits(currAPD, aAPD); |
6720 | 0 | } else { |
6721 | 0 | // Looks like aOther wasn't an ancestor of |this|. So now we have |
6722 | 0 | // the root-document-relative position of |this| in |offset|. Subtract the |
6723 | 0 | // root-document-relative position of |aOther| from |offset|. |
6724 | 0 | // This call won't try to recurse again because root is an ancestor of |
6725 | 0 | // aOther. |
6726 | 0 | nsPoint negOffset = aOther->GetOffsetToCrossDoc(root, aAPD); |
6727 | 0 | offset -= negOffset; |
6728 | 0 | } |
6729 | 0 |
|
6730 | 0 | return offset; |
6731 | 0 | } |
6732 | | |
6733 | | CSSIntRect nsIFrame::GetScreenRect() const |
6734 | 0 | { |
6735 | 0 | return CSSIntRect::FromAppUnitsToNearest(GetScreenRectInAppUnits()); |
6736 | 0 | } |
6737 | | |
6738 | | nsRect nsIFrame::GetScreenRectInAppUnits() const |
6739 | 0 | { |
6740 | 0 | nsPresContext* presContext = PresContext(); |
6741 | 0 | nsIFrame* rootFrame = |
6742 | 0 | presContext->PresShell()->GetRootFrame(); |
6743 | 0 | nsPoint rootScreenPos(0, 0); |
6744 | 0 | nsPoint rootFrameOffsetInParent(0, 0); |
6745 | 0 | nsIFrame* rootFrameParent = |
6746 | 0 | nsLayoutUtils::GetCrossDocParentFrame(rootFrame, &rootFrameOffsetInParent); |
6747 | 0 | if (rootFrameParent) { |
6748 | 0 | nsRect parentScreenRectAppUnits = rootFrameParent->GetScreenRectInAppUnits(); |
6749 | 0 | nsPresContext* parentPresContext = rootFrameParent->PresContext(); |
6750 | 0 | double parentScale = double(presContext->AppUnitsPerDevPixel())/ |
6751 | 0 | parentPresContext->AppUnitsPerDevPixel(); |
6752 | 0 | nsPoint rootPt = parentScreenRectAppUnits.TopLeft() + rootFrameOffsetInParent; |
6753 | 0 | rootScreenPos.x = NS_round(parentScale*rootPt.x); |
6754 | 0 | rootScreenPos.y = NS_round(parentScale*rootPt.y); |
6755 | 0 | } else { |
6756 | 0 | nsCOMPtr<nsIWidget> rootWidget; |
6757 | 0 | presContext->PresShell()->GetViewManager()->GetRootWidget(getter_AddRefs(rootWidget)); |
6758 | 0 | if (rootWidget) { |
6759 | 0 | LayoutDeviceIntPoint rootDevPx = rootWidget->WidgetToScreenOffset(); |
6760 | 0 | rootScreenPos.x = presContext->DevPixelsToAppUnits(rootDevPx.x); |
6761 | 0 | rootScreenPos.y = presContext->DevPixelsToAppUnits(rootDevPx.y); |
6762 | 0 | } |
6763 | 0 | } |
6764 | 0 |
|
6765 | 0 | return nsRect(rootScreenPos + GetOffsetTo(rootFrame), GetSize()); |
6766 | 0 | } |
6767 | | |
6768 | | // Returns the offset from this frame to the closest geometric parent that |
6769 | | // has a view. Also returns the containing view or null in case of error |
6770 | | void |
6771 | | nsIFrame::GetOffsetFromView(nsPoint& aOffset, nsView** aView) const |
6772 | 0 | { |
6773 | 0 | MOZ_ASSERT(nullptr != aView, "null OUT parameter pointer"); |
6774 | 0 | nsIFrame* frame = const_cast<nsIFrame*>(this); |
6775 | 0 |
|
6776 | 0 | *aView = nullptr; |
6777 | 0 | aOffset.MoveTo(0, 0); |
6778 | 0 | do { |
6779 | 0 | aOffset += frame->GetPosition(); |
6780 | 0 | frame = frame->GetParent(); |
6781 | 0 | } while (frame && !frame->HasView()); |
6782 | 0 |
|
6783 | 0 | if (frame) { |
6784 | 0 | *aView = frame->GetView(); |
6785 | 0 | } |
6786 | 0 | } |
6787 | | |
6788 | | nsIWidget* |
6789 | | nsIFrame::GetNearestWidget() const |
6790 | 0 | { |
6791 | 0 | return GetClosestView()->GetNearestWidget(nullptr); |
6792 | 0 | } |
6793 | | |
6794 | | nsIWidget* |
6795 | | nsIFrame::GetNearestWidget(nsPoint& aOffset) const |
6796 | 0 | { |
6797 | 0 | nsPoint offsetToView; |
6798 | 0 | nsPoint offsetToWidget; |
6799 | 0 | nsIWidget* widget = |
6800 | 0 | GetClosestView(&offsetToView)->GetNearestWidget(&offsetToWidget); |
6801 | 0 | aOffset = offsetToView + offsetToWidget; |
6802 | 0 | return widget; |
6803 | 0 | } |
6804 | | |
6805 | | Matrix4x4Flagged |
6806 | | nsIFrame::GetTransformMatrix(const nsIFrame* aStopAtAncestor, |
6807 | | nsIFrame** aOutAncestor, |
6808 | | uint32_t aFlags) const |
6809 | 0 | { |
6810 | 0 | MOZ_ASSERT(aOutAncestor, "Need a place to put the ancestor!"); |
6811 | 0 |
|
6812 | 0 | /* If we're transformed, we want to hand back the combination |
6813 | 0 | * transform/translate matrix that will apply our current transform, then |
6814 | 0 | * shift us to our parent. |
6815 | 0 | */ |
6816 | 0 | if (IsTransformed()) { |
6817 | 0 | /* Compute the delta to the parent, which we need because we are converting |
6818 | 0 | * coordinates to our parent. |
6819 | 0 | */ |
6820 | 0 | NS_ASSERTION(nsLayoutUtils::GetCrossDocParentFrame(this), |
6821 | 0 | "Cannot transform the viewport frame!"); |
6822 | 0 | int32_t scaleFactor = ((aFlags & IN_CSS_UNITS) ? AppUnitsPerCSSPixel() |
6823 | 0 | : PresContext()->AppUnitsPerDevPixel()); |
6824 | 0 |
|
6825 | 0 | Matrix4x4 result = nsDisplayTransform::GetResultingTransformMatrix(this, |
6826 | 0 | nsPoint(0,0), scaleFactor, |
6827 | 0 | nsDisplayTransform::INCLUDE_PERSPECTIVE|nsDisplayTransform::OFFSET_BY_ORIGIN, |
6828 | 0 | nullptr); |
6829 | 0 | *aOutAncestor = nsLayoutUtils::GetCrossDocParentFrame(this); |
6830 | 0 | nsPoint delta = GetOffsetToCrossDoc(*aOutAncestor); |
6831 | 0 | /* Combine the raw transform with a translation to our parent. */ |
6832 | 0 | result.PostTranslate(NSAppUnitsToFloatPixels(delta.x, scaleFactor), |
6833 | 0 | NSAppUnitsToFloatPixels(delta.y, scaleFactor), |
6834 | 0 | 0.0f); |
6835 | 0 |
|
6836 | 0 | return result; |
6837 | 0 | } |
6838 | 0 |
|
6839 | 0 | if (nsLayoutUtils::IsPopup(this) && IsListControlFrame()) { |
6840 | 0 | nsPresContext* presContext = PresContext(); |
6841 | 0 | nsIFrame* docRootFrame = presContext->PresShell()->GetRootFrame(); |
6842 | 0 |
|
6843 | 0 | // Compute a matrix that transforms from the popup widget to the toplevel |
6844 | 0 | // widget. We use the widgets because they're the simplest and most |
6845 | 0 | // accurate approach --- this should work no matter how the widget position |
6846 | 0 | // was chosen. |
6847 | 0 | nsIWidget* widget = GetView()->GetWidget(); |
6848 | 0 | nsPresContext* rootPresContext = PresContext()->GetRootPresContext(); |
6849 | 0 | // Maybe the widget hasn't been created yet? Popups without widgets are |
6850 | 0 | // treated as regular frames. That should work since they'll be rendered |
6851 | 0 | // as part of the page if they're rendered at all. |
6852 | 0 | if (widget && rootPresContext) { |
6853 | 0 | nsIWidget* toplevel = rootPresContext->GetNearestWidget(); |
6854 | 0 | if (toplevel) { |
6855 | 0 | LayoutDeviceIntRect screenBounds = widget->GetClientBounds(); |
6856 | 0 | LayoutDeviceIntRect toplevelScreenBounds = toplevel->GetClientBounds(); |
6857 | 0 | LayoutDeviceIntPoint translation = |
6858 | 0 | screenBounds.TopLeft() - toplevelScreenBounds.TopLeft(); |
6859 | 0 |
|
6860 | 0 | Matrix4x4 transformToTop; |
6861 | 0 | transformToTop._41 = translation.x; |
6862 | 0 | transformToTop._42 = translation.y; |
6863 | 0 |
|
6864 | 0 | *aOutAncestor = docRootFrame; |
6865 | 0 | Matrix4x4 docRootTransformToTop = |
6866 | 0 | nsLayoutUtils::GetTransformToAncestor(docRootFrame, nullptr).GetMatrix(); |
6867 | 0 | if (docRootTransformToTop.IsSingular()) { |
6868 | 0 | NS_WARNING("Containing document is invisible, we can't compute a valid transform"); |
6869 | 0 | } else { |
6870 | 0 | docRootTransformToTop.Invert(); |
6871 | 0 | return transformToTop * docRootTransformToTop; |
6872 | 0 | } |
6873 | 0 | } |
6874 | 0 | } |
6875 | 0 | } |
6876 | 0 | |
6877 | 0 | *aOutAncestor = nsLayoutUtils::GetCrossDocParentFrame(this); |
6878 | 0 |
|
6879 | 0 | /* Otherwise, we're not transformed. In that case, we'll walk up the frame |
6880 | 0 | * tree until we either hit the root frame or something that may be |
6881 | 0 | * transformed. We'll then change coordinates into that frame, since we're |
6882 | 0 | * guaranteed that nothing in-between can be transformed. First, however, |
6883 | 0 | * we have to check to see if we have a parent. If not, we'll set the |
6884 | 0 | * outparam to null (indicating that there's nothing left) and will hand back |
6885 | 0 | * the identity matrix. |
6886 | 0 | */ |
6887 | 0 | if (!*aOutAncestor) |
6888 | 0 | return Matrix4x4(); |
6889 | 0 | |
6890 | 0 | /* Keep iterating while the frame can't possibly be transformed. */ |
6891 | 0 | const nsIFrame* current = this; |
6892 | 0 | while (!(*aOutAncestor)->IsTransformed() && |
6893 | 0 | !nsLayoutUtils::IsPopup(*aOutAncestor) && |
6894 | 0 | *aOutAncestor != aStopAtAncestor && |
6895 | 0 | (!(aFlags & STOP_AT_STACKING_CONTEXT_AND_DISPLAY_PORT) || |
6896 | 0 | (!(*aOutAncestor)->IsStackingContext() && !nsLayoutUtils::FrameHasDisplayPort(*aOutAncestor, current)))) { |
6897 | 0 | /* If no parent, stop iterating. Otherwise, update the ancestor. */ |
6898 | 0 | nsIFrame* parent = nsLayoutUtils::GetCrossDocParentFrame(*aOutAncestor); |
6899 | 0 | if (!parent) |
6900 | 0 | break; |
6901 | 0 | |
6902 | 0 | current = *aOutAncestor; |
6903 | 0 | *aOutAncestor = parent; |
6904 | 0 | } |
6905 | 0 |
|
6906 | 0 | NS_ASSERTION(*aOutAncestor, "Somehow ended up with a null ancestor...?"); |
6907 | 0 |
|
6908 | 0 | /* Translate from this frame to our ancestor, if it exists. That's the |
6909 | 0 | * entire transform, so we're done. |
6910 | 0 | */ |
6911 | 0 | nsPoint delta = GetOffsetToCrossDoc(*aOutAncestor); |
6912 | 0 | int32_t scaleFactor = ((aFlags & IN_CSS_UNITS) ? AppUnitsPerCSSPixel() |
6913 | 0 | : PresContext()->AppUnitsPerDevPixel()); |
6914 | 0 | return Matrix4x4::Translation(NSAppUnitsToFloatPixels(delta.x, scaleFactor), |
6915 | 0 | NSAppUnitsToFloatPixels(delta.y, scaleFactor), |
6916 | 0 | 0.0f); |
6917 | 0 | } |
6918 | | |
6919 | | static void InvalidateRenderingObservers(nsIFrame* aDisplayRoot, nsIFrame* aFrame, bool aFrameChanged = true) |
6920 | 0 | { |
6921 | 0 | MOZ_ASSERT(aDisplayRoot == nsLayoutUtils::GetDisplayRootFrame(aFrame)); |
6922 | 0 | SVGObserverUtils::InvalidateDirectRenderingObservers(aFrame); |
6923 | 0 | nsIFrame* parent = aFrame; |
6924 | 0 | while (parent != aDisplayRoot && |
6925 | 0 | (parent = nsLayoutUtils::GetCrossDocParentFrame(parent)) && |
6926 | 0 | !parent->HasAnyStateBits(NS_FRAME_DESCENDANT_NEEDS_PAINT)) { |
6927 | 0 | SVGObserverUtils::InvalidateDirectRenderingObservers(parent); |
6928 | 0 | } |
6929 | 0 |
|
6930 | 0 | if (!aFrameChanged) { |
6931 | 0 | return; |
6932 | 0 | } |
6933 | 0 | |
6934 | 0 | aFrame->MarkNeedsDisplayItemRebuild(); |
6935 | 0 | } |
6936 | | |
6937 | | static void |
6938 | | SchedulePaintInternal(nsIFrame* aDisplayRoot, nsIFrame* aFrame, |
6939 | | nsIFrame::PaintType aType = nsIFrame::PAINT_DEFAULT) |
6940 | 0 | { |
6941 | 0 | MOZ_ASSERT(aDisplayRoot == nsLayoutUtils::GetDisplayRootFrame(aFrame)); |
6942 | 0 | nsPresContext* pres = aDisplayRoot->PresContext()->GetRootPresContext(); |
6943 | 0 |
|
6944 | 0 | // No need to schedule a paint for an external document since they aren't |
6945 | 0 | // painted directly. |
6946 | 0 | if (!pres || (pres->Document() && pres->Document()->IsResourceDoc())) { |
6947 | 0 | return; |
6948 | 0 | } |
6949 | 0 | if (!pres->GetContainerWeak()) { |
6950 | 0 | NS_WARNING("Shouldn't call SchedulePaint in a detached pres context"); |
6951 | 0 | return; |
6952 | 0 | } |
6953 | 0 |
|
6954 | 0 | pres->PresShell()->ScheduleViewManagerFlush(aType == nsIFrame::PAINT_DELAYED_COMPRESS ? |
6955 | 0 | nsIPresShell::PAINT_DELAYED_COMPRESS : |
6956 | 0 | nsIPresShell::PAINT_DEFAULT); |
6957 | 0 |
|
6958 | 0 | if (aType == nsIFrame::PAINT_DELAYED_COMPRESS) { |
6959 | 0 | return; |
6960 | 0 | } |
6961 | 0 | |
6962 | 0 | if (aType == nsIFrame::PAINT_DEFAULT) { |
6963 | 0 | aDisplayRoot->AddStateBits(NS_FRAME_UPDATE_LAYER_TREE); |
6964 | 0 | } |
6965 | 0 | } |
6966 | | |
6967 | | static void InvalidateFrameInternal(nsIFrame *aFrame, bool aHasDisplayItem, bool aRebuildDisplayItems) |
6968 | 0 | { |
6969 | 0 | if (aHasDisplayItem) { |
6970 | 0 | aFrame->AddStateBits(NS_FRAME_NEEDS_PAINT); |
6971 | 0 | } |
6972 | 0 |
|
6973 | 0 | if (aRebuildDisplayItems) { |
6974 | 0 | aFrame->MarkNeedsDisplayItemRebuild(); |
6975 | 0 | } |
6976 | 0 | SVGObserverUtils::InvalidateDirectRenderingObservers(aFrame); |
6977 | 0 | bool needsSchedulePaint = false; |
6978 | 0 | if (nsLayoutUtils::IsPopup(aFrame)) { |
6979 | 0 | needsSchedulePaint = true; |
6980 | 0 | } else { |
6981 | 0 | nsIFrame *parent = nsLayoutUtils::GetCrossDocParentFrame(aFrame); |
6982 | 0 | while (parent && !parent->HasAnyStateBits(NS_FRAME_DESCENDANT_NEEDS_PAINT)) { |
6983 | 0 | if (aHasDisplayItem && !parent->HasAnyStateBits(NS_FRAME_IS_NONDISPLAY)) { |
6984 | 0 | parent->AddStateBits(NS_FRAME_DESCENDANT_NEEDS_PAINT); |
6985 | 0 | } |
6986 | 0 | SVGObserverUtils::InvalidateDirectRenderingObservers(parent); |
6987 | 0 |
|
6988 | 0 | // If we're inside a popup, then we need to make sure that we |
6989 | 0 | // call schedule paint so that the NS_FRAME_UPDATE_LAYER_TREE |
6990 | 0 | // flag gets added to the popup display root frame. |
6991 | 0 | if (nsLayoutUtils::IsPopup(parent)) { |
6992 | 0 | needsSchedulePaint = true; |
6993 | 0 | break; |
6994 | 0 | } |
6995 | 0 | parent = nsLayoutUtils::GetCrossDocParentFrame(parent); |
6996 | 0 | } |
6997 | 0 | if (!parent) { |
6998 | 0 | needsSchedulePaint = true; |
6999 | 0 | } |
7000 | 0 | } |
7001 | 0 | if (!aHasDisplayItem) { |
7002 | 0 | return; |
7003 | 0 | } |
7004 | 0 | if (needsSchedulePaint) { |
7005 | 0 | nsIFrame* displayRoot = nsLayoutUtils::GetDisplayRootFrame(aFrame); |
7006 | 0 | SchedulePaintInternal(displayRoot, aFrame); |
7007 | 0 | } |
7008 | 0 | if (aFrame->HasAnyStateBits(NS_FRAME_HAS_INVALID_RECT)) { |
7009 | 0 | aFrame->DeleteProperty(nsIFrame::InvalidationRect()); |
7010 | 0 | aFrame->RemoveStateBits(NS_FRAME_HAS_INVALID_RECT); |
7011 | 0 | } |
7012 | 0 | } |
7013 | | |
7014 | | void |
7015 | | nsIFrame::InvalidateFrameSubtree(bool aRebuildDisplayItems /* = true */) |
7016 | 0 | { |
7017 | 0 | InvalidateFrame(0, aRebuildDisplayItems); |
7018 | 0 |
|
7019 | 0 | if (HasAnyStateBits(NS_FRAME_ALL_DESCENDANTS_NEED_PAINT)) { |
7020 | 0 | return; |
7021 | 0 | } |
7022 | 0 | |
7023 | 0 | AddStateBits(NS_FRAME_ALL_DESCENDANTS_NEED_PAINT); |
7024 | 0 |
|
7025 | 0 | AutoTArray<nsIFrame::ChildList,4> childListArray; |
7026 | 0 | GetCrossDocChildLists(&childListArray); |
7027 | 0 |
|
7028 | 0 | nsIFrame::ChildListArrayIterator lists(childListArray); |
7029 | 0 | for (; !lists.IsDone(); lists.Next()) { |
7030 | 0 | nsFrameList::Enumerator childFrames(lists.CurrentList()); |
7031 | 0 | for (; !childFrames.AtEnd(); childFrames.Next()) { |
7032 | 0 | // Don't explicitly rebuild display items for our descendants, |
7033 | 0 | // since we should be marked and it implicitly includes all |
7034 | 0 | // descendants. |
7035 | 0 | childFrames.get()->InvalidateFrameSubtree(false); |
7036 | 0 | } |
7037 | 0 | } |
7038 | 0 | } |
7039 | | |
7040 | | void |
7041 | | nsIFrame::ClearInvalidationStateBits() |
7042 | 0 | { |
7043 | 0 | if (HasAnyStateBits(NS_FRAME_DESCENDANT_NEEDS_PAINT)) { |
7044 | 0 | AutoTArray<nsIFrame::ChildList,4> childListArray; |
7045 | 0 | GetCrossDocChildLists(&childListArray); |
7046 | 0 |
|
7047 | 0 | nsIFrame::ChildListArrayIterator lists(childListArray); |
7048 | 0 | for (; !lists.IsDone(); lists.Next()) { |
7049 | 0 | nsFrameList::Enumerator childFrames(lists.CurrentList()); |
7050 | 0 | for (; !childFrames.AtEnd(); childFrames.Next()) { |
7051 | 0 | childFrames.get()->ClearInvalidationStateBits(); |
7052 | 0 | } |
7053 | 0 | } |
7054 | 0 | } |
7055 | 0 |
|
7056 | 0 | RemoveStateBits(NS_FRAME_NEEDS_PAINT | |
7057 | 0 | NS_FRAME_DESCENDANT_NEEDS_PAINT | |
7058 | 0 | NS_FRAME_ALL_DESCENDANTS_NEED_PAINT); |
7059 | 0 | } |
7060 | | |
7061 | | void |
7062 | | nsIFrame::InvalidateFrame(uint32_t aDisplayItemKey, bool aRebuildDisplayItems /* = true */) |
7063 | 0 | { |
7064 | 0 | bool hasDisplayItem = |
7065 | 0 | !aDisplayItemKey || FrameLayerBuilder::HasRetainedDataFor(this, aDisplayItemKey); |
7066 | 0 | InvalidateFrameInternal(this, hasDisplayItem, aRebuildDisplayItems); |
7067 | 0 | } |
7068 | | |
7069 | | void |
7070 | | nsIFrame::InvalidateFrameWithRect(const nsRect& aRect, uint32_t aDisplayItemKey, bool aRebuildDisplayItems /* = true */) |
7071 | 0 | { |
7072 | 0 | if (aRect.IsEmpty()) { |
7073 | 0 | return; |
7074 | 0 | } |
7075 | 0 | bool hasDisplayItem = |
7076 | 0 | !aDisplayItemKey || FrameLayerBuilder::HasRetainedDataFor(this, aDisplayItemKey); |
7077 | 0 | bool alreadyInvalid = false; |
7078 | 0 | if (!HasAnyStateBits(NS_FRAME_NEEDS_PAINT)) { |
7079 | 0 | InvalidateFrameInternal(this, hasDisplayItem, aRebuildDisplayItems); |
7080 | 0 | } else { |
7081 | 0 | alreadyInvalid = true; |
7082 | 0 | } |
7083 | 0 |
|
7084 | 0 | if (!hasDisplayItem) { |
7085 | 0 | return; |
7086 | 0 | } |
7087 | 0 | |
7088 | 0 | nsRect* rect; |
7089 | 0 | if (HasAnyStateBits(NS_FRAME_HAS_INVALID_RECT)) { |
7090 | 0 | rect = GetProperty(InvalidationRect()); |
7091 | 0 | MOZ_ASSERT(rect); |
7092 | 0 | } else { |
7093 | 0 | if (alreadyInvalid) { |
7094 | 0 | return; |
7095 | 0 | } |
7096 | 0 | rect = new nsRect(); |
7097 | 0 | AddProperty(InvalidationRect(), rect); |
7098 | 0 | AddStateBits(NS_FRAME_HAS_INVALID_RECT); |
7099 | 0 | } |
7100 | 0 |
|
7101 | 0 | *rect = rect->Union(aRect); |
7102 | 0 | } |
7103 | | |
7104 | | /*static*/ uint8_t nsIFrame::sLayerIsPrerenderedDataKey; |
7105 | | |
7106 | | static bool |
7107 | | DoesLayerHaveOutOfDateFrameMetrics(Layer* aLayer) |
7108 | 0 | { |
7109 | 0 | for (uint32_t i = 0; i < aLayer->GetScrollMetadataCount(); i++) { |
7110 | 0 | const FrameMetrics& metrics = aLayer->GetFrameMetrics(i); |
7111 | 0 | if (!metrics.IsScrollable()) { |
7112 | 0 | continue; |
7113 | 0 | } |
7114 | 0 | nsIScrollableFrame* scrollableFrame = |
7115 | 0 | nsLayoutUtils::FindScrollableFrameFor(metrics.GetScrollId()); |
7116 | 0 | if (!scrollableFrame) { |
7117 | 0 | // This shouldn't happen, so let's do the safe thing and trigger a full |
7118 | 0 | // paint if it does. |
7119 | 0 | return true; |
7120 | 0 | } |
7121 | 0 | nsPoint scrollPosition = scrollableFrame->GetScrollPosition(); |
7122 | 0 | if (metrics.GetScrollOffset() != CSSPoint::FromAppUnits(scrollPosition)) { |
7123 | 0 | return true; |
7124 | 0 | } |
7125 | 0 | } |
7126 | 0 | return false; |
7127 | 0 | } |
7128 | | |
7129 | | static bool |
7130 | | DoesLayerOrAncestorsHaveOutOfDateFrameMetrics(Layer* aLayer) |
7131 | 0 | { |
7132 | 0 | for (Layer* layer = aLayer; layer; layer = layer->GetParent()) { |
7133 | 0 | if (DoesLayerHaveOutOfDateFrameMetrics(layer)) { |
7134 | 0 | return true; |
7135 | 0 | } |
7136 | 0 | } |
7137 | 0 | return false; |
7138 | 0 | } |
7139 | | |
7140 | | bool |
7141 | | nsIFrame::TryUpdateTransformOnly(Layer** aLayerResult) |
7142 | 0 | { |
7143 | 0 | // If we move a transformed layer when we have a merged display |
7144 | 0 | // list, then it can end up intersecting other items for which |
7145 | 0 | // we don't have a defined ordering. |
7146 | 0 | // We could allow this if the display list is in the canonical |
7147 | 0 | // ordering (correctly sorted for all intersections), but we |
7148 | 0 | // don't have a way to check that yet. |
7149 | 0 | if (nsLayoutUtils::AreRetainedDisplayListsEnabled()) { |
7150 | 0 | return false; |
7151 | 0 | } |
7152 | 0 | |
7153 | 0 | Layer* layer = FrameLayerBuilder::GetDedicatedLayer( |
7154 | 0 | this, DisplayItemType::TYPE_TRANSFORM); |
7155 | 0 | if (!layer || !layer->HasUserData(LayerIsPrerenderedDataKey())) { |
7156 | 0 | // If this layer isn't prerendered or we clip composites to our OS |
7157 | 0 | // window, then we can't correctly optimize to an empty |
7158 | 0 | // transaction in general. |
7159 | 0 | return false; |
7160 | 0 | } |
7161 | 0 | |
7162 | 0 | if (DoesLayerOrAncestorsHaveOutOfDateFrameMetrics(layer)) { |
7163 | 0 | // At least one scroll frame that can affect the position of this layer |
7164 | 0 | // has changed its scroll offset since the last paint. Schedule a full |
7165 | 0 | // paint to make sure that this layer's transform and all the frame |
7166 | 0 | // metrics that affect it are in sync. |
7167 | 0 | return false; |
7168 | 0 | } |
7169 | 0 | |
7170 | 0 | gfx::Matrix4x4Flagged transform3d; |
7171 | 0 | if (!nsLayoutUtils::GetLayerTransformForFrame(this, &transform3d)) { |
7172 | 0 | // We're not able to compute a layer transform that we know would |
7173 | 0 | // be used at the next layers transaction, so we can't only update |
7174 | 0 | // the transform and will need to schedule an invalidating paint. |
7175 | 0 | return false; |
7176 | 0 | } |
7177 | 0 | gfx::Matrix transform; |
7178 | 0 | gfx::Matrix previousTransform; |
7179 | 0 | // FIXME/bug 796690 and 796705: in general, changes to 3D |
7180 | 0 | // transforms, or transform changes to properties other than |
7181 | 0 | // translation, may lead us to choose a different rendering |
7182 | 0 | // resolution for our layer. So if the transform is 3D or has a |
7183 | 0 | // non-translation change, bail and schedule an invalidating paint. |
7184 | 0 | // (We can often do better than this, for example for scale-down |
7185 | 0 | // changes.) |
7186 | 0 | static const gfx::Float kError = 0.0001f; |
7187 | 0 | if (!transform3d.Is2D(&transform) || |
7188 | 0 | !layer->GetBaseTransform().Is2D(&previousTransform) || |
7189 | 0 | !gfx::FuzzyEqual(transform._11, previousTransform._11, kError) || |
7190 | 0 | !gfx::FuzzyEqual(transform._22, previousTransform._22, kError) || |
7191 | 0 | !gfx::FuzzyEqual(transform._21, previousTransform._21, kError) || |
7192 | 0 | !gfx::FuzzyEqual(transform._12, previousTransform._12, kError)) { |
7193 | 0 | return false; |
7194 | 0 | } |
7195 | 0 | layer->SetBaseTransformForNextTransaction(transform3d.GetMatrix()); |
7196 | 0 | *aLayerResult = layer; |
7197 | 0 | return true; |
7198 | 0 | } |
7199 | | |
7200 | | bool |
7201 | | nsIFrame::IsInvalid(nsRect& aRect) |
7202 | 0 | { |
7203 | 0 | if (!HasAnyStateBits(NS_FRAME_NEEDS_PAINT)) { |
7204 | 0 | return false; |
7205 | 0 | } |
7206 | 0 | |
7207 | 0 | if (HasAnyStateBits(NS_FRAME_HAS_INVALID_RECT)) { |
7208 | 0 | nsRect* rect = GetProperty(InvalidationRect()); |
7209 | 0 | NS_ASSERTION(rect, "Must have an invalid rect if NS_FRAME_HAS_INVALID_RECT is set!"); |
7210 | 0 | aRect = *rect; |
7211 | 0 | } else { |
7212 | 0 | aRect.SetEmpty(); |
7213 | 0 | } |
7214 | 0 | return true; |
7215 | 0 | } |
7216 | | |
7217 | | void |
7218 | | nsIFrame::SchedulePaint(PaintType aType, bool aFrameChanged) |
7219 | 0 | { |
7220 | 0 | nsIFrame* displayRoot = nsLayoutUtils::GetDisplayRootFrame(this); |
7221 | 0 | InvalidateRenderingObservers(displayRoot, this, aFrameChanged); |
7222 | 0 | SchedulePaintInternal(displayRoot, this, aType); |
7223 | 0 | } |
7224 | | |
7225 | | void |
7226 | | nsIFrame::SchedulePaintWithoutInvalidatingObservers(PaintType aType) |
7227 | 0 | { |
7228 | 0 | nsIFrame* displayRoot = nsLayoutUtils::GetDisplayRootFrame(this); |
7229 | 0 | SchedulePaintInternal(displayRoot, this, aType); |
7230 | 0 | } |
7231 | | |
7232 | | Layer* |
7233 | | nsIFrame::InvalidateLayer(DisplayItemType aDisplayItemKey, |
7234 | | const nsIntRect* aDamageRect, |
7235 | | const nsRect* aFrameDamageRect, |
7236 | | uint32_t aFlags /* = 0 */) |
7237 | 0 | { |
7238 | 0 | NS_ASSERTION(aDisplayItemKey > DisplayItemType::TYPE_ZERO, "Need a key"); |
7239 | 0 |
|
7240 | 0 | Layer* layer = FrameLayerBuilder::GetDedicatedLayer(this, aDisplayItemKey); |
7241 | 0 |
|
7242 | 0 | nsIFrame* displayRoot = nsLayoutUtils::GetDisplayRootFrame(this); |
7243 | 0 | InvalidateRenderingObservers(displayRoot, this); |
7244 | 0 |
|
7245 | 0 | // Check if frame supports WebRender's async update |
7246 | 0 | if ((aFlags & UPDATE_IS_ASYNC) && |
7247 | 0 | WebRenderUserData::SupportsAsyncUpdate(this)) { |
7248 | 0 | // WebRender does not use layer, then return nullptr. |
7249 | 0 | return nullptr; |
7250 | 0 | } |
7251 | 0 | |
7252 | 0 | // If the layer is being updated asynchronously, and it's being forwarded |
7253 | 0 | // to a compositor, then we don't need to invalidate. |
7254 | 0 | if ((aFlags & UPDATE_IS_ASYNC) && layer && layer->SupportsAsyncUpdate()) { |
7255 | 0 | return layer; |
7256 | 0 | } |
7257 | 0 | |
7258 | 0 | if (!layer) { |
7259 | 0 | if (aFrameDamageRect && aFrameDamageRect->IsEmpty()) { |
7260 | 0 | return nullptr; |
7261 | 0 | } |
7262 | 0 | |
7263 | 0 | // Plugins can transition from not rendering anything to rendering, |
7264 | 0 | // and still only call this. So always invalidate, with specifying |
7265 | 0 | // the display item type just in case. |
7266 | 0 | // |
7267 | 0 | // In the bug 930056, dialer app startup but not shown on the |
7268 | 0 | // screen because sometimes we don't have any retainned data |
7269 | 0 | // for remote type displayitem and thus Repaint event is not |
7270 | 0 | // triggered. So, always invalidate here as well. |
7271 | 0 | DisplayItemType displayItemKey = aDisplayItemKey; |
7272 | 0 | if (aDisplayItemKey == DisplayItemType::TYPE_PLUGIN || |
7273 | 0 | aDisplayItemKey == DisplayItemType::TYPE_REMOTE) { |
7274 | 0 | displayItemKey = DisplayItemType::TYPE_ZERO; |
7275 | 0 | } |
7276 | 0 |
|
7277 | 0 | if (aFrameDamageRect) { |
7278 | 0 | InvalidateFrameWithRect(*aFrameDamageRect, static_cast<uint32_t>(displayItemKey)); |
7279 | 0 | } else { |
7280 | 0 | InvalidateFrame(static_cast<uint32_t>(displayItemKey)); |
7281 | 0 | } |
7282 | 0 |
|
7283 | 0 | return nullptr; |
7284 | 0 | } |
7285 | 0 |
|
7286 | 0 | if (aDamageRect && aDamageRect->IsEmpty()) { |
7287 | 0 | return layer; |
7288 | 0 | } |
7289 | 0 | |
7290 | 0 | if (aDamageRect) { |
7291 | 0 | layer->AddInvalidRect(*aDamageRect); |
7292 | 0 | } else { |
7293 | 0 | layer->SetInvalidRectToVisibleRegion(); |
7294 | 0 | } |
7295 | 0 |
|
7296 | 0 | SchedulePaintInternal(displayRoot, this, PAINT_COMPOSITE_ONLY); |
7297 | 0 | return layer; |
7298 | 0 | } |
7299 | | |
7300 | | static nsRect |
7301 | | ComputeEffectsRect(nsIFrame* aFrame, const nsRect& aOverflowRect, |
7302 | | const nsSize& aNewSize) |
7303 | 0 | { |
7304 | 0 | nsRect r = aOverflowRect; |
7305 | 0 |
|
7306 | 0 | if (aFrame->GetStateBits() & NS_FRAME_SVG_LAYOUT) { |
7307 | 0 | // For SVG frames, we only need to account for filters. |
7308 | 0 | // TODO: We could also take account of clipPath and mask to reduce the |
7309 | 0 | // visual overflow, but that's not essential. |
7310 | 0 | if (aFrame->StyleEffects()->HasFilters()) { |
7311 | 0 | aFrame->SetProperty |
7312 | 0 | (nsIFrame::PreEffectsBBoxProperty(), new nsRect(r)); |
7313 | 0 | r = nsSVGUtils::GetPostFilterVisualOverflowRect(aFrame, aOverflowRect); |
7314 | 0 | } |
7315 | 0 | return r; |
7316 | 0 | } |
7317 | 0 |
|
7318 | 0 | // box-shadow |
7319 | 0 | r.UnionRect(r, nsLayoutUtils::GetBoxShadowRectForFrame(aFrame, aNewSize)); |
7320 | 0 |
|
7321 | 0 | // border-image-outset. |
7322 | 0 | // We need to include border-image-outset because it can cause the |
7323 | 0 | // border image to be drawn beyond the border box. |
7324 | 0 |
|
7325 | 0 | // (1) It's important we not check whether there's a border-image |
7326 | 0 | // since the style hint for a change in border image doesn't cause |
7327 | 0 | // reflow, and that's probably more important than optimizing the |
7328 | 0 | // overflow areas for the silly case of border-image-outset without |
7329 | 0 | // border-image |
7330 | 0 | // (2) It's important that we not check whether the border-image |
7331 | 0 | // is actually loaded, since that would require us to reflow when |
7332 | 0 | // the image loads. |
7333 | 0 | const nsStyleBorder* styleBorder = aFrame->StyleBorder(); |
7334 | 0 | nsMargin outsetMargin = styleBorder->GetImageOutset(); |
7335 | 0 |
|
7336 | 0 | if (outsetMargin != nsMargin(0, 0, 0, 0)) { |
7337 | 0 | nsRect outsetRect(nsPoint(0, 0), aNewSize); |
7338 | 0 | outsetRect.Inflate(outsetMargin); |
7339 | 0 | r.UnionRect(r, outsetRect); |
7340 | 0 | } |
7341 | 0 |
|
7342 | 0 | // Note that we don't remove the outlineInnerRect if a frame loses outline |
7343 | 0 | // style. That would require an extra property lookup for every frame, |
7344 | 0 | // or a new frame state bit to track whether a property had been stored, |
7345 | 0 | // or something like that. It's not worth doing that here. At most it's |
7346 | 0 | // only one heap-allocated rect per frame and it will be cleaned up when |
7347 | 0 | // the frame dies. |
7348 | 0 |
|
7349 | 0 | if (nsSVGIntegrationUtils::UsingEffectsForFrame(aFrame)) { |
7350 | 0 | aFrame->SetProperty |
7351 | 0 | (nsIFrame::PreEffectsBBoxProperty(), new nsRect(r)); |
7352 | 0 | r = nsSVGIntegrationUtils::ComputePostEffectsVisualOverflowRect(aFrame, r); |
7353 | 0 | } |
7354 | 0 |
|
7355 | 0 | return r; |
7356 | 0 | } |
7357 | | |
7358 | | void |
7359 | | nsIFrame::MovePositionBy(const nsPoint& aTranslation) |
7360 | 0 | { |
7361 | 0 | nsPoint position = GetNormalPosition() + aTranslation; |
7362 | 0 |
|
7363 | 0 | const nsMargin* computedOffsets = nullptr; |
7364 | 0 | if (IsRelativelyPositioned()) { |
7365 | 0 | computedOffsets = GetProperty(nsIFrame::ComputedOffsetProperty()); |
7366 | 0 | } |
7367 | 0 | ReflowInput::ApplyRelativePositioning(this, computedOffsets ? |
7368 | 0 | *computedOffsets : nsMargin(), |
7369 | 0 | &position); |
7370 | 0 | SetPosition(position); |
7371 | 0 | } |
7372 | | |
7373 | | nsRect |
7374 | | nsIFrame::GetNormalRect() const |
7375 | 0 | { |
7376 | 0 | // It might be faster to first check |
7377 | 0 | // StyleDisplay()->IsRelativelyPositionedStyle(). |
7378 | 0 | nsPoint* normalPosition = GetProperty(NormalPositionProperty()); |
7379 | 0 | if (normalPosition) { |
7380 | 0 | return nsRect(*normalPosition, GetSize()); |
7381 | 0 | } |
7382 | 0 | return GetRect(); |
7383 | 0 | } |
7384 | | |
7385 | | nsPoint |
7386 | | nsIFrame::GetPositionIgnoringScrolling() const |
7387 | 0 | { |
7388 | 0 | return GetParent() ? GetParent()->GetPositionOfChildIgnoringScrolling(this) |
7389 | 0 | : GetPosition(); |
7390 | 0 | } |
7391 | | |
7392 | | nsRect |
7393 | | nsIFrame::GetOverflowRect(nsOverflowType aType) const |
7394 | 0 | { |
7395 | 0 | MOZ_ASSERT(aType == eVisualOverflow || aType == eScrollableOverflow, |
7396 | 0 | "unexpected type"); |
7397 | 0 |
|
7398 | 0 | // Note that in some cases the overflow area might not have been |
7399 | 0 | // updated (yet) to reflect any outline set on the frame or the area |
7400 | 0 | // of child frames. That's OK because any reflow that updates these |
7401 | 0 | // areas will invalidate the appropriate area, so any (mis)uses of |
7402 | 0 | // this method will be fixed up. |
7403 | 0 |
|
7404 | 0 | if (mOverflow.mType == NS_FRAME_OVERFLOW_LARGE) { |
7405 | 0 | // there is an overflow rect, and it's not stored as deltas but as |
7406 | 0 | // a separately-allocated rect |
7407 | 0 | return GetOverflowAreasProperty()->Overflow(aType); |
7408 | 0 | } |
7409 | 0 | |
7410 | 0 | if (aType == eVisualOverflow && |
7411 | 0 | mOverflow.mType != NS_FRAME_OVERFLOW_NONE) { |
7412 | 0 | return GetVisualOverflowFromDeltas(); |
7413 | 0 | } |
7414 | 0 | |
7415 | 0 | return nsRect(nsPoint(0, 0), GetSize()); |
7416 | 0 | } |
7417 | | |
7418 | | nsOverflowAreas |
7419 | | nsIFrame::GetOverflowAreas() const |
7420 | 0 | { |
7421 | 0 | if (mOverflow.mType == NS_FRAME_OVERFLOW_LARGE) { |
7422 | 0 | // there is an overflow rect, and it's not stored as deltas but as |
7423 | 0 | // a separately-allocated rect |
7424 | 0 | return *GetOverflowAreasProperty(); |
7425 | 0 | } |
7426 | 0 | |
7427 | 0 | return nsOverflowAreas(GetVisualOverflowFromDeltas(), |
7428 | 0 | nsRect(nsPoint(0, 0), GetSize())); |
7429 | 0 | } |
7430 | | |
7431 | | nsOverflowAreas |
7432 | | nsIFrame::GetOverflowAreasRelativeToSelf() const |
7433 | 0 | { |
7434 | 0 | if (IsTransformed()) { |
7435 | 0 | nsOverflowAreas* preTransformOverflows = |
7436 | 0 | GetProperty(PreTransformOverflowAreasProperty()); |
7437 | 0 | if (preTransformOverflows) { |
7438 | 0 | return nsOverflowAreas(preTransformOverflows->VisualOverflow(), |
7439 | 0 | preTransformOverflows->ScrollableOverflow()); |
7440 | 0 | } |
7441 | 0 | } |
7442 | 0 | return nsOverflowAreas(GetVisualOverflowRect(), |
7443 | 0 | GetScrollableOverflowRect()); |
7444 | 0 | } |
7445 | | |
7446 | | nsRect |
7447 | | nsIFrame::GetScrollableOverflowRectRelativeToParent() const |
7448 | 0 | { |
7449 | 0 | return GetScrollableOverflowRect() + mRect.TopLeft(); |
7450 | 0 | } |
7451 | | |
7452 | | nsRect |
7453 | | nsIFrame::GetVisualOverflowRectRelativeToParent() const |
7454 | 0 | { |
7455 | 0 | return GetVisualOverflowRect() + mRect.TopLeft(); |
7456 | 0 | } |
7457 | | |
7458 | | nsRect |
7459 | | nsIFrame::GetScrollableOverflowRectRelativeToSelf() const |
7460 | 0 | { |
7461 | 0 | if (IsTransformed()) { |
7462 | 0 | nsOverflowAreas* preTransformOverflows = |
7463 | 0 | GetProperty(PreTransformOverflowAreasProperty()); |
7464 | 0 | if (preTransformOverflows) |
7465 | 0 | return preTransformOverflows->ScrollableOverflow(); |
7466 | 0 | } |
7467 | 0 | return GetScrollableOverflowRect(); |
7468 | 0 | } |
7469 | | |
7470 | | nsRect |
7471 | | nsIFrame::GetVisualOverflowRectRelativeToSelf() const |
7472 | 0 | { |
7473 | 0 | if (IsTransformed()) { |
7474 | 0 | nsOverflowAreas* preTransformOverflows = |
7475 | 0 | GetProperty(PreTransformOverflowAreasProperty()); |
7476 | 0 | if (preTransformOverflows) |
7477 | 0 | return preTransformOverflows->VisualOverflow(); |
7478 | 0 | } |
7479 | 0 | return GetVisualOverflowRect(); |
7480 | 0 | } |
7481 | | |
7482 | | nsRect |
7483 | | nsIFrame::GetPreEffectsVisualOverflowRect() const |
7484 | 0 | { |
7485 | 0 | nsRect* r = GetProperty(nsIFrame::PreEffectsBBoxProperty()); |
7486 | 0 | return r ? *r : GetVisualOverflowRectRelativeToSelf(); |
7487 | 0 | } |
7488 | | |
7489 | | bool |
7490 | | nsIFrame::UpdateOverflow() |
7491 | 0 | { |
7492 | 0 | MOZ_ASSERT(FrameMaintainsOverflow(), |
7493 | 0 | "Non-display SVG do not maintain visual overflow rects"); |
7494 | 0 |
|
7495 | 0 | nsRect rect(nsPoint(0, 0), GetSize()); |
7496 | 0 | nsOverflowAreas overflowAreas(rect, rect); |
7497 | 0 |
|
7498 | 0 | if (!ComputeCustomOverflow(overflowAreas)) { |
7499 | 0 | return false; |
7500 | 0 | } |
7501 | 0 | |
7502 | 0 | UnionChildOverflow(overflowAreas); |
7503 | 0 |
|
7504 | 0 | if (FinishAndStoreOverflow(overflowAreas, GetSize())) { |
7505 | 0 | nsView* view = GetView(); |
7506 | 0 | if (view) { |
7507 | 0 | uint32_t flags = GetXULLayoutFlags(); |
7508 | 0 |
|
7509 | 0 | if ((flags & NS_FRAME_NO_SIZE_VIEW) == 0) { |
7510 | 0 | // Make sure the frame's view is properly sized. |
7511 | 0 | nsViewManager* vm = view->GetViewManager(); |
7512 | 0 | vm->ResizeView(view, overflowAreas.VisualOverflow(), true); |
7513 | 0 | } |
7514 | 0 | } |
7515 | 0 |
|
7516 | 0 | return true; |
7517 | 0 | } |
7518 | 0 |
|
7519 | 0 | return false; |
7520 | 0 | } |
7521 | | |
7522 | | /* virtual */ bool |
7523 | | nsFrame::ComputeCustomOverflow(nsOverflowAreas& aOverflowAreas) |
7524 | 0 | { |
7525 | 0 | return true; |
7526 | 0 | } |
7527 | | |
7528 | | /* virtual */ void |
7529 | | nsFrame::UnionChildOverflow(nsOverflowAreas& aOverflowAreas) |
7530 | 0 | { |
7531 | 0 | if (!DoesClipChildren() && |
7532 | 0 | !(IsXULCollapsed() && (IsXULBoxFrame() || ::IsXULBoxWrapped(this)))) { |
7533 | 0 | nsLayoutUtils::UnionChildOverflow(this, aOverflowAreas); |
7534 | 0 | } |
7535 | 0 | } |
7536 | | |
7537 | | |
7538 | | // Define the MAX_FRAME_DEPTH to be the ContentSink's MAX_REFLOW_DEPTH plus |
7539 | | // 4 for the frames above the document's frames: |
7540 | | // the Viewport, GFXScroll, ScrollPort, and Canvas |
7541 | 0 | #define MAX_FRAME_DEPTH (MAX_REFLOW_DEPTH+4) |
7542 | | |
7543 | | bool |
7544 | | nsFrame::IsFrameTreeTooDeep(const ReflowInput& aReflowInput, |
7545 | | ReflowOutput& aMetrics, |
7546 | | nsReflowStatus& aStatus) |
7547 | 0 | { |
7548 | 0 | if (aReflowInput.mReflowDepth > MAX_FRAME_DEPTH) { |
7549 | 0 | NS_WARNING("frame tree too deep; setting zero size and returning"); |
7550 | 0 | AddStateBits(NS_FRAME_TOO_DEEP_IN_FRAME_TREE); |
7551 | 0 | ClearOverflowRects(); |
7552 | 0 | aMetrics.ClearSize(); |
7553 | 0 | aMetrics.SetBlockStartAscent(0); |
7554 | 0 | aMetrics.mCarriedOutBEndMargin.Zero(); |
7555 | 0 | aMetrics.mOverflowAreas.Clear(); |
7556 | 0 |
|
7557 | 0 | aStatus.Reset(); |
7558 | 0 | if (GetNextInFlow()) { |
7559 | 0 | // Reflow depth might vary between reflows, so we might have |
7560 | 0 | // successfully reflowed and split this frame before. If so, we |
7561 | 0 | // shouldn't delete its continuations. |
7562 | 0 | aStatus.SetIncomplete(); |
7563 | 0 | } |
7564 | 0 |
|
7565 | 0 | return true; |
7566 | 0 | } |
7567 | 0 | RemoveStateBits(NS_FRAME_TOO_DEEP_IN_FRAME_TREE); |
7568 | 0 | return false; |
7569 | 0 | } |
7570 | | |
7571 | | bool |
7572 | | nsIFrame::IsBlockWrapper() const |
7573 | 0 | { |
7574 | 0 | nsAtom *pseudoType = Style()->GetPseudo(); |
7575 | 0 | return (pseudoType == nsCSSAnonBoxes::mozBlockInsideInlineWrapper() || |
7576 | 0 | pseudoType == nsCSSAnonBoxes::buttonContent() || |
7577 | 0 | pseudoType == nsCSSAnonBoxes::cellContent()); |
7578 | 0 | } |
7579 | | |
7580 | | static nsIFrame* |
7581 | | GetNearestBlockContainer(nsIFrame* frame) |
7582 | 0 | { |
7583 | 0 | // The block wrappers we use to wrap blocks inside inlines aren't |
7584 | 0 | // described in the CSS spec. We need to make them not be containing |
7585 | 0 | // blocks. |
7586 | 0 | // Since the parent of such a block is either a normal block or |
7587 | 0 | // another such pseudo, this shouldn't cause anything bad to happen. |
7588 | 0 | // Also the anonymous blocks inside table cells are not containing blocks. |
7589 | 0 | // |
7590 | 0 | // If we ever start skipping table row groups from being containing blocks, |
7591 | 0 | // you need to remove the StickyScrollContainer hack referencing bug 1421660. |
7592 | 0 | while (frame->IsFrameOfType(nsIFrame::eLineParticipant) || |
7593 | 0 | frame->IsBlockWrapper() || |
7594 | 0 | // Table rows are not containing blocks either |
7595 | 0 | frame->IsTableRowFrame()) { |
7596 | 0 | frame = frame->GetParent(); |
7597 | 0 | NS_ASSERTION(frame, "How come we got to the root frame without seeing a containing block?"); |
7598 | 0 | } |
7599 | 0 | return frame; |
7600 | 0 | } |
7601 | | |
7602 | | nsIFrame* |
7603 | | nsIFrame::GetContainingBlock(uint32_t aFlags, |
7604 | | const nsStyleDisplay* aStyleDisplay) const |
7605 | 0 | { |
7606 | 0 | MOZ_ASSERT(aStyleDisplay == StyleDisplay()); |
7607 | 0 | if (!GetParent()) { |
7608 | 0 | return nullptr; |
7609 | 0 | } |
7610 | 0 | // MathML frames might have absolute positioning style, but they would |
7611 | 0 | // still be in-flow. So we have to check to make sure that the frame |
7612 | 0 | // is really out-of-flow too. |
7613 | 0 | nsIFrame* f; |
7614 | 0 | if (IsAbsolutelyPositioned(aStyleDisplay) && |
7615 | 0 | (GetStateBits() & NS_FRAME_OUT_OF_FLOW)) { |
7616 | 0 | f = GetParent(); // the parent is always the containing block |
7617 | 0 | } else { |
7618 | 0 | f = GetNearestBlockContainer(GetParent()); |
7619 | 0 | } |
7620 | 0 |
|
7621 | 0 | if (aFlags & SKIP_SCROLLED_FRAME && f && |
7622 | 0 | f->Style()->GetPseudo() == nsCSSAnonBoxes::scrolledContent()) { |
7623 | 0 | f = f->GetParent(); |
7624 | 0 | } |
7625 | 0 | return f; |
7626 | 0 | } |
7627 | | |
7628 | | #ifdef DEBUG_FRAME_DUMP |
7629 | | |
7630 | | int32_t nsFrame::ContentIndexInContainer(const nsIFrame* aFrame) |
7631 | | { |
7632 | | int32_t result = -1; |
7633 | | |
7634 | | nsIContent* content = aFrame->GetContent(); |
7635 | | if (content) { |
7636 | | nsIContent* parentContent = content->GetParent(); |
7637 | | if (parentContent) { |
7638 | | result = parentContent->ComputeIndexOf(content); |
7639 | | } |
7640 | | } |
7641 | | |
7642 | | return result; |
7643 | | } |
7644 | | |
7645 | | /** |
7646 | | * List a frame tree to stderr. Meant to be called from gdb. |
7647 | | */ |
7648 | | void |
7649 | | DebugListFrameTree(nsIFrame* aFrame) |
7650 | | { |
7651 | | ((nsFrame*)aFrame)->List(stderr); |
7652 | | } |
7653 | | |
7654 | | void |
7655 | | nsIFrame::ListTag(nsACString& aTo) const |
7656 | | { |
7657 | | ListTag(aTo, this); |
7658 | | } |
7659 | | |
7660 | | /* static */ |
7661 | | void |
7662 | | nsIFrame::ListTag(nsACString& aTo, const nsIFrame* aFrame) { |
7663 | | nsAutoString tmp; |
7664 | | aFrame->GetFrameName(tmp); |
7665 | | aTo += NS_ConvertUTF16toUTF8(tmp).get(); |
7666 | | aTo += nsPrintfCString("@%p", static_cast<const void*>(aFrame)); |
7667 | | } |
7668 | | |
7669 | | // Debugging |
7670 | | void |
7671 | | nsIFrame::ListGeneric(nsACString& aTo, const char* aPrefix, uint32_t aFlags) const |
7672 | | { |
7673 | | aTo += aPrefix; |
7674 | | ListTag(aTo); |
7675 | | if (HasView()) { |
7676 | | aTo += nsPrintfCString(" [view=%p]", static_cast<void*>(GetView())); |
7677 | | } |
7678 | | if (GetParent()) { |
7679 | | aTo += nsPrintfCString(" parent=%p", static_cast<void*>(GetParent())); |
7680 | | } |
7681 | | if (GetNextSibling()) { |
7682 | | aTo += nsPrintfCString(" next=%p", static_cast<void*>(GetNextSibling())); |
7683 | | } |
7684 | | if (GetPrevContinuation()) { |
7685 | | bool fluid = GetPrevInFlow() == GetPrevContinuation(); |
7686 | | aTo += nsPrintfCString(" prev-%s=%p", fluid?"in-flow":"continuation", |
7687 | | static_cast<void*>(GetPrevContinuation())); |
7688 | | } |
7689 | | if (GetNextContinuation()) { |
7690 | | bool fluid = GetNextInFlow() == GetNextContinuation(); |
7691 | | aTo += nsPrintfCString(" next-%s=%p", fluid?"in-flow":"continuation", |
7692 | | static_cast<void*>(GetNextContinuation())); |
7693 | | } |
7694 | | void* IBsibling = GetProperty(IBSplitSibling()); |
7695 | | if (IBsibling) { |
7696 | | aTo += nsPrintfCString(" IBSplitSibling=%p", IBsibling); |
7697 | | } |
7698 | | void* IBprevsibling = GetProperty(IBSplitPrevSibling()); |
7699 | | if (IBprevsibling) { |
7700 | | aTo += nsPrintfCString(" IBSplitPrevSibling=%p", IBprevsibling); |
7701 | | } |
7702 | | aTo += nsPrintfCString(" {%d,%d,%d,%d}", mRect.x, mRect.y, mRect.width, mRect.height); |
7703 | | |
7704 | | mozilla::WritingMode wm = GetWritingMode(); |
7705 | | if (wm.IsVertical() || !wm.IsBidiLTR()) { |
7706 | | aTo += nsPrintfCString(" wm=%s: logical size={%d,%d}", wm.DebugString(), |
7707 | | ISize(), BSize()); |
7708 | | } |
7709 | | |
7710 | | nsIFrame* parent = GetParent(); |
7711 | | if (parent) { |
7712 | | WritingMode pWM = parent->GetWritingMode(); |
7713 | | if (pWM.IsVertical() || !pWM.IsBidiLTR()) { |
7714 | | nsSize containerSize = parent->mRect.Size(); |
7715 | | LogicalRect lr(pWM, mRect, containerSize); |
7716 | | aTo += nsPrintfCString(" parent wm=%s, cs={%d,%d}, " |
7717 | | " logicalRect={%d,%d,%d,%d}", |
7718 | | pWM.DebugString(), |
7719 | | containerSize.width, containerSize.height, |
7720 | | lr.IStart(pWM), lr.BStart(pWM), |
7721 | | lr.ISize(pWM), lr.BSize(pWM)); |
7722 | | } |
7723 | | } |
7724 | | nsIFrame* f = const_cast<nsIFrame*>(this); |
7725 | | if (f->HasOverflowAreas()) { |
7726 | | nsRect vo = f->GetVisualOverflowRect(); |
7727 | | if (!vo.IsEqualEdges(mRect)) { |
7728 | | aTo += nsPrintfCString(" vis-overflow=%d,%d,%d,%d", vo.x, vo.y, vo.width, vo.height); |
7729 | | } |
7730 | | nsRect so = f->GetScrollableOverflowRect(); |
7731 | | if (!so.IsEqualEdges(mRect)) { |
7732 | | aTo += nsPrintfCString(" scr-overflow=%d,%d,%d,%d", so.x, so.y, so.width, so.height); |
7733 | | } |
7734 | | } |
7735 | | if (0 != mState) { |
7736 | | aTo += nsPrintfCString(" [state=%016llx]", (unsigned long long)mState); |
7737 | | } |
7738 | | if (HasProperty(BidiDataProperty())) { |
7739 | | FrameBidiData bidi = GetBidiData(); |
7740 | | aTo += nsPrintfCString(" bidi(%d,%d,%d)", bidi.baseLevel, |
7741 | | bidi.embeddingLevel, bidi.precedingControl); |
7742 | | } |
7743 | | if (IsTransformed()) { |
7744 | | aTo += nsPrintfCString(" transformed"); |
7745 | | } |
7746 | | if (ChildrenHavePerspective()) { |
7747 | | aTo += nsPrintfCString(" perspective"); |
7748 | | } |
7749 | | if (Extend3DContext()) { |
7750 | | aTo += nsPrintfCString(" extend-3d"); |
7751 | | } |
7752 | | if (Combines3DTransformWithAncestors()) { |
7753 | | aTo += nsPrintfCString(" combines-3d-transform-with-ancestors"); |
7754 | | } |
7755 | | if (mContent) { |
7756 | | aTo += nsPrintfCString(" [content=%p]", static_cast<void*>(mContent)); |
7757 | | } |
7758 | | aTo += nsPrintfCString(" [cs=%p", static_cast<void*>(mComputedStyle)); |
7759 | | if (mComputedStyle) { |
7760 | | nsAtom* pseudoTag = mComputedStyle->GetPseudo(); |
7761 | | if (pseudoTag) { |
7762 | | nsAutoString atomString; |
7763 | | pseudoTag->ToString(atomString); |
7764 | | aTo += nsPrintfCString("%s", NS_LossyConvertUTF16toASCII(atomString).get()); |
7765 | | } |
7766 | | } |
7767 | | aTo += "]"; |
7768 | | } |
7769 | | |
7770 | | void |
7771 | | nsIFrame::List(FILE* out, const char* aPrefix, uint32_t aFlags) const |
7772 | | { |
7773 | | nsCString str; |
7774 | | ListGeneric(str, aPrefix, aFlags); |
7775 | | fprintf_stderr(out, "%s\n", str.get()); |
7776 | | } |
7777 | | |
7778 | | nsresult |
7779 | | nsFrame::GetFrameName(nsAString& aResult) const |
7780 | | { |
7781 | | return MakeFrameName(NS_LITERAL_STRING("Frame"), aResult); |
7782 | | } |
7783 | | |
7784 | | nsresult |
7785 | | nsFrame::MakeFrameName(const nsAString& aType, nsAString& aResult) const |
7786 | | { |
7787 | | aResult = aType; |
7788 | | if (mContent && !mContent->IsText()) { |
7789 | | nsAutoString buf; |
7790 | | mContent->NodeInfo()->NameAtom()->ToString(buf); |
7791 | | if (IsSubDocumentFrame()) { |
7792 | | nsAutoString src; |
7793 | | mContent->AsElement()->GetAttr(kNameSpaceID_None, nsGkAtoms::src, src); |
7794 | | buf.AppendLiteral(" src="); |
7795 | | buf.Append(src); |
7796 | | } |
7797 | | aResult.Append('('); |
7798 | | aResult.Append(buf); |
7799 | | aResult.Append(')'); |
7800 | | } |
7801 | | aResult.Append('('); |
7802 | | aResult.AppendInt(ContentIndexInContainer(this)); |
7803 | | aResult.Append(')'); |
7804 | | return NS_OK; |
7805 | | } |
7806 | | |
7807 | | void |
7808 | | nsIFrame::DumpFrameTree() const |
7809 | | { |
7810 | | RootFrameList(PresContext(), stderr); |
7811 | | } |
7812 | | |
7813 | | void |
7814 | | nsIFrame::DumpFrameTreeLimited() const |
7815 | | { |
7816 | | List(stderr); |
7817 | | } |
7818 | | |
7819 | | void |
7820 | | nsIFrame::RootFrameList(nsPresContext* aPresContext, FILE* out, const char* aPrefix) |
7821 | | { |
7822 | | if (!aPresContext || !out) |
7823 | | return; |
7824 | | |
7825 | | nsIPresShell *shell = aPresContext->GetPresShell(); |
7826 | | if (shell) { |
7827 | | nsIFrame* frame = shell->GetRootFrame(); |
7828 | | if(frame) { |
7829 | | frame->List(out, aPrefix); |
7830 | | } |
7831 | | } |
7832 | | } |
7833 | | #endif |
7834 | | |
7835 | | bool |
7836 | 0 | nsIFrame::IsVisibleForPainting(nsDisplayListBuilder* aBuilder) { |
7837 | 0 | if (!StyleVisibility()->IsVisible()) |
7838 | 0 | return false; |
7839 | 0 | Selection* sel = aBuilder->GetBoundingSelection(); |
7840 | 0 | return !sel || IsVisibleInSelection(sel); |
7841 | 0 | } |
7842 | | |
7843 | | bool |
7844 | 0 | nsIFrame::IsVisibleForPainting() { |
7845 | 0 | if (!StyleVisibility()->IsVisible()) |
7846 | 0 | return false; |
7847 | 0 | |
7848 | 0 | nsPresContext* pc = PresContext(); |
7849 | 0 | if (!pc->IsRenderingOnlySelection()) |
7850 | 0 | return true; |
7851 | 0 | |
7852 | 0 | nsCOMPtr<nsISelectionController> selcon(do_QueryInterface(pc->PresShell())); |
7853 | 0 | if (selcon) { |
7854 | 0 | RefPtr<Selection> sel = |
7855 | 0 | selcon->GetSelection(nsISelectionController::SELECTION_NORMAL); |
7856 | 0 | if (sel) { |
7857 | 0 | return IsVisibleInSelection(sel); |
7858 | 0 | } |
7859 | 0 | } |
7860 | 0 | return true; |
7861 | 0 | } |
7862 | | |
7863 | | bool |
7864 | 0 | nsIFrame::IsVisibleInSelection(nsDisplayListBuilder* aBuilder) { |
7865 | 0 | Selection* sel = aBuilder->GetBoundingSelection(); |
7866 | 0 | return !sel || IsVisibleInSelection(sel); |
7867 | 0 | } |
7868 | | |
7869 | | bool |
7870 | 0 | nsIFrame::IsVisibleOrCollapsedForPainting(nsDisplayListBuilder* aBuilder) { |
7871 | 0 | if (!StyleVisibility()->IsVisibleOrCollapsed()) |
7872 | 0 | return false; |
7873 | 0 | Selection* sel = aBuilder->GetBoundingSelection(); |
7874 | 0 | return !sel || IsVisibleInSelection(sel); |
7875 | 0 | } |
7876 | | |
7877 | | bool |
7878 | | nsIFrame::IsVisibleInSelection(Selection* aSelection) |
7879 | 0 | { |
7880 | 0 | if (!GetContent() || !GetContent()->IsSelectionDescendant()) { |
7881 | 0 | return false; |
7882 | 0 | } |
7883 | 0 | |
7884 | 0 | ErrorResult rv; |
7885 | 0 | bool vis = aSelection->ContainsNode(*mContent, true, rv); |
7886 | 0 | return rv.Failed() || vis; |
7887 | 0 | } |
7888 | | |
7889 | | /* virtual */ bool |
7890 | | nsFrame::IsEmpty() |
7891 | 0 | { |
7892 | 0 | return false; |
7893 | 0 | } |
7894 | | |
7895 | | bool |
7896 | | nsIFrame::CachedIsEmpty() |
7897 | 0 | { |
7898 | 0 | MOZ_ASSERT(!(GetStateBits() & NS_FRAME_IS_DIRTY), |
7899 | 0 | "Must only be called on reflowed lines"); |
7900 | 0 | return IsEmpty(); |
7901 | 0 | } |
7902 | | |
7903 | | /* virtual */ bool |
7904 | | nsFrame::IsSelfEmpty() |
7905 | 0 | { |
7906 | 0 | return false; |
7907 | 0 | } |
7908 | | |
7909 | | nsresult |
7910 | | nsFrame::GetSelectionController(nsPresContext *aPresContext, nsISelectionController **aSelCon) |
7911 | 0 | { |
7912 | 0 | if (!aPresContext || !aSelCon) |
7913 | 0 | return NS_ERROR_INVALID_ARG; |
7914 | 0 | |
7915 | 0 | nsIFrame *frame = this; |
7916 | 0 | while (frame && (frame->GetStateBits() & NS_FRAME_INDEPENDENT_SELECTION)) { |
7917 | 0 | nsITextControlFrame *tcf = do_QueryFrame(frame); |
7918 | 0 | if (tcf) { |
7919 | 0 | return tcf->GetOwnedSelectionController(aSelCon); |
7920 | 0 | } |
7921 | 0 | frame = frame->GetParent(); |
7922 | 0 | } |
7923 | 0 |
|
7924 | 0 | return CallQueryInterface(aPresContext->GetPresShell(), aSelCon); |
7925 | 0 | } |
7926 | | |
7927 | | already_AddRefed<nsFrameSelection> |
7928 | | nsIFrame::GetFrameSelection() |
7929 | 0 | { |
7930 | 0 | RefPtr<nsFrameSelection> fs = |
7931 | 0 | const_cast<nsFrameSelection*>(GetConstFrameSelection()); |
7932 | 0 | return fs.forget(); |
7933 | 0 | } |
7934 | | |
7935 | | const nsFrameSelection* |
7936 | | nsIFrame::GetConstFrameSelection() const |
7937 | 0 | { |
7938 | 0 | nsIFrame* frame = const_cast<nsIFrame*>(this); |
7939 | 0 | while (frame && (frame->GetStateBits() & NS_FRAME_INDEPENDENT_SELECTION)) { |
7940 | 0 | nsITextControlFrame* tcf = do_QueryFrame(frame); |
7941 | 0 | if (tcf) { |
7942 | 0 | return tcf->GetOwnedFrameSelection(); |
7943 | 0 | } |
7944 | 0 | frame = frame->GetParent(); |
7945 | 0 | } |
7946 | 0 |
|
7947 | 0 | return PresShell()->ConstFrameSelection(); |
7948 | 0 | } |
7949 | | |
7950 | | bool |
7951 | | nsIFrame::IsFrameSelected() const |
7952 | 0 | { |
7953 | 0 | NS_ASSERTION(!GetContent() || GetContent()->IsSelectionDescendant(), |
7954 | 0 | "use the public IsSelected() instead"); |
7955 | 0 | return nsRange::IsNodeSelected(GetContent(), 0, |
7956 | 0 | GetContent()->GetChildCount()); |
7957 | 0 | } |
7958 | | |
7959 | | nsresult |
7960 | | nsFrame::GetPointFromOffset(int32_t inOffset, nsPoint* outPoint) |
7961 | 0 | { |
7962 | 0 | MOZ_ASSERT(outPoint != nullptr, "Null parameter"); |
7963 | 0 | nsRect contentRect = GetContentRectRelativeToSelf(); |
7964 | 0 | nsPoint pt = contentRect.TopLeft(); |
7965 | 0 | if (mContent) |
7966 | 0 | { |
7967 | 0 | nsIContent* newContent = mContent->GetParent(); |
7968 | 0 | if (newContent){ |
7969 | 0 | int32_t newOffset = newContent->ComputeIndexOf(mContent); |
7970 | 0 |
|
7971 | 0 | // Find the direction of the frame from the EmbeddingLevelProperty, |
7972 | 0 | // which is the resolved bidi level set in |
7973 | 0 | // nsBidiPresUtils::ResolveParagraph (odd levels = right-to-left). |
7974 | 0 | // If the embedding level isn't set, just use the CSS direction |
7975 | 0 | // property. |
7976 | 0 | bool hasBidiData; |
7977 | 0 | FrameBidiData bidiData = GetProperty(BidiDataProperty(), &hasBidiData); |
7978 | 0 | bool isRTL = hasBidiData |
7979 | 0 | ? IS_LEVEL_RTL(bidiData.embeddingLevel) |
7980 | 0 | : StyleVisibility()->mDirection == NS_STYLE_DIRECTION_RTL; |
7981 | 0 | if ((!isRTL && inOffset > newOffset) || |
7982 | 0 | (isRTL && inOffset <= newOffset)) { |
7983 | 0 | pt = contentRect.TopRight(); |
7984 | 0 | } |
7985 | 0 | } |
7986 | 0 | } |
7987 | 0 | *outPoint = pt; |
7988 | 0 | return NS_OK; |
7989 | 0 | } |
7990 | | |
7991 | | nsresult |
7992 | | nsFrame::GetCharacterRectsInRange(int32_t aInOffset, int32_t aLength, |
7993 | | nsTArray<nsRect>& aOutRect) |
7994 | 0 | { |
7995 | 0 | /* no text */ |
7996 | 0 | return NS_ERROR_FAILURE; |
7997 | 0 | } |
7998 | | |
7999 | | nsresult |
8000 | | nsFrame::GetChildFrameContainingOffset(int32_t inContentOffset, bool inHint, int32_t* outFrameContentOffset, nsIFrame **outChildFrame) |
8001 | 0 | { |
8002 | 0 | MOZ_ASSERT(outChildFrame && outFrameContentOffset, "Null parameter"); |
8003 | 0 | *outFrameContentOffset = (int32_t)inHint; |
8004 | 0 | //the best frame to reflect any given offset would be a visible frame if possible |
8005 | 0 | //i.e. we are looking for a valid frame to place the blinking caret |
8006 | 0 | nsRect rect = GetRect(); |
8007 | 0 | if (!rect.width || !rect.height) |
8008 | 0 | { |
8009 | 0 | //if we have a 0 width or height then lets look for another frame that possibly has |
8010 | 0 | //the same content. If we have no frames in flow then just let us return 'this' frame |
8011 | 0 | nsIFrame* nextFlow = GetNextInFlow(); |
8012 | 0 | if (nextFlow) |
8013 | 0 | return nextFlow->GetChildFrameContainingOffset(inContentOffset, inHint, outFrameContentOffset, outChildFrame); |
8014 | 0 | } |
8015 | 0 | *outChildFrame = this; |
8016 | 0 | return NS_OK; |
8017 | 0 | } |
8018 | | |
8019 | | // |
8020 | | // What I've pieced together about this routine: |
8021 | | // Starting with a block frame (from which a line frame can be gotten) |
8022 | | // and a line number, drill down and get the first/last selectable |
8023 | | // frame on that line, depending on aPos->mDirection. |
8024 | | // aOutSideLimit != 0 means ignore aLineStart, instead work from |
8025 | | // the end (if > 0) or beginning (if < 0). |
8026 | | // |
8027 | | nsresult |
8028 | | nsFrame::GetNextPrevLineFromeBlockFrame(nsPresContext* aPresContext, |
8029 | | nsPeekOffsetStruct *aPos, |
8030 | | nsIFrame *aBlockFrame, |
8031 | | int32_t aLineStart, |
8032 | | int8_t aOutSideLimit |
8033 | | ) |
8034 | 0 | { |
8035 | 0 | //magic numbers aLineStart will be -1 for end of block 0 will be start of block |
8036 | 0 | if (!aBlockFrame || !aPos) |
8037 | 0 | return NS_ERROR_NULL_POINTER; |
8038 | 0 | |
8039 | 0 | aPos->mResultFrame = nullptr; |
8040 | 0 | aPos->mResultContent = nullptr; |
8041 | 0 | aPos->mAttach = |
8042 | 0 | aPos->mDirection == eDirNext ? CARET_ASSOCIATE_AFTER : CARET_ASSOCIATE_BEFORE; |
8043 | 0 |
|
8044 | 0 | nsAutoLineIterator it = aBlockFrame->GetLineIterator(); |
8045 | 0 | if (!it) |
8046 | 0 | return NS_ERROR_FAILURE; |
8047 | 0 | int32_t searchingLine = aLineStart; |
8048 | 0 | int32_t countLines = it->GetNumLines(); |
8049 | 0 | if (aOutSideLimit > 0) //start at end |
8050 | 0 | searchingLine = countLines; |
8051 | 0 | else if (aOutSideLimit <0)//start at beginning |
8052 | 0 | searchingLine = -1;//"next" will be 0 |
8053 | 0 | else |
8054 | 0 | if ((aPos->mDirection == eDirPrevious && searchingLine == 0) || |
8055 | 0 | (aPos->mDirection == eDirNext && searchingLine >= (countLines -1) )){ |
8056 | 0 | //we need to jump to new block frame. |
8057 | 0 | return NS_ERROR_FAILURE; |
8058 | 0 | } |
8059 | 0 | int32_t lineFrameCount; |
8060 | 0 | nsIFrame *resultFrame = nullptr; |
8061 | 0 | nsIFrame *farStoppingFrame = nullptr; //we keep searching until we find a "this" frame then we go to next line |
8062 | 0 | nsIFrame *nearStoppingFrame = nullptr; //if we are backing up from edge, stop here |
8063 | 0 | nsIFrame *firstFrame; |
8064 | 0 | nsIFrame *lastFrame; |
8065 | 0 | nsRect rect; |
8066 | 0 | bool isBeforeFirstFrame, isAfterLastFrame; |
8067 | 0 | bool found = false; |
8068 | 0 |
|
8069 | 0 | nsresult result = NS_OK; |
8070 | 0 | while (!found) |
8071 | 0 | { |
8072 | 0 | if (aPos->mDirection == eDirPrevious) |
8073 | 0 | searchingLine --; |
8074 | 0 | else |
8075 | 0 | searchingLine ++; |
8076 | 0 | if ((aPos->mDirection == eDirPrevious && searchingLine < 0) || |
8077 | 0 | (aPos->mDirection == eDirNext && searchingLine >= countLines )) |
8078 | 0 | { |
8079 | 0 | //we need to jump to new block frame. |
8080 | 0 | return NS_ERROR_FAILURE; |
8081 | 0 | } |
8082 | 0 | result = it->GetLine(searchingLine, &firstFrame, &lineFrameCount, |
8083 | 0 | rect); |
8084 | 0 | if (!lineFrameCount) |
8085 | 0 | continue; |
8086 | 0 | if (NS_SUCCEEDED(result)){ |
8087 | 0 | lastFrame = firstFrame; |
8088 | 0 | for (;lineFrameCount > 1;lineFrameCount --){ |
8089 | 0 | //result = lastFrame->GetNextSibling(&lastFrame, searchingLine); |
8090 | 0 | result = it->GetNextSiblingOnLine(lastFrame, searchingLine); |
8091 | 0 | if (NS_FAILED(result) || !lastFrame){ |
8092 | 0 | NS_ERROR("GetLine promised more frames than could be found"); |
8093 | 0 | return NS_ERROR_FAILURE; |
8094 | 0 | } |
8095 | 0 | } |
8096 | 0 | GetLastLeaf(aPresContext, &lastFrame); |
8097 | 0 |
|
8098 | 0 | if (aPos->mDirection == eDirNext){ |
8099 | 0 | nearStoppingFrame = firstFrame; |
8100 | 0 | farStoppingFrame = lastFrame; |
8101 | 0 | } |
8102 | 0 | else{ |
8103 | 0 | nearStoppingFrame = lastFrame; |
8104 | 0 | farStoppingFrame = firstFrame; |
8105 | 0 | } |
8106 | 0 | nsPoint offset; |
8107 | 0 | nsView * view; //used for call of get offset from view |
8108 | 0 | aBlockFrame->GetOffsetFromView(offset,&view); |
8109 | 0 | nsPoint newDesiredPos = |
8110 | 0 | aPos->mDesiredPos - offset; //get desired position into blockframe coords |
8111 | 0 | result = it->FindFrameAt(searchingLine, newDesiredPos, &resultFrame, |
8112 | 0 | &isBeforeFirstFrame, &isAfterLastFrame); |
8113 | 0 | if(NS_FAILED(result)) |
8114 | 0 | continue; |
8115 | 0 | } |
8116 | 0 | |
8117 | 0 | if (NS_SUCCEEDED(result) && resultFrame) |
8118 | 0 | { |
8119 | 0 | //check to see if this is ANOTHER blockframe inside the other one if so then call into its lines |
8120 | 0 | nsAutoLineIterator newIt = resultFrame->GetLineIterator(); |
8121 | 0 | if (newIt) |
8122 | 0 | { |
8123 | 0 | aPos->mResultFrame = resultFrame; |
8124 | 0 | return NS_OK; |
8125 | 0 | } |
8126 | 0 | //resultFrame is not a block frame |
8127 | 0 | result = NS_ERROR_FAILURE; |
8128 | 0 |
|
8129 | 0 | nsCOMPtr<nsIFrameEnumerator> frameTraversal; |
8130 | 0 | result = NS_NewFrameTraversal(getter_AddRefs(frameTraversal), |
8131 | 0 | aPresContext, resultFrame, |
8132 | 0 | ePostOrder, |
8133 | 0 | false, // aVisual |
8134 | 0 | aPos->mScrollViewStop, |
8135 | 0 | false, // aFollowOOFs |
8136 | 0 | false // aSkipPopupChecks |
8137 | 0 | ); |
8138 | 0 | if (NS_FAILED(result)) |
8139 | 0 | return result; |
8140 | 0 | |
8141 | 0 | nsIFrame *storeOldResultFrame = resultFrame; |
8142 | 0 | while ( !found ){ |
8143 | 0 | nsPoint point; |
8144 | 0 | nsRect tempRect = resultFrame->GetRect(); |
8145 | 0 | nsPoint offset; |
8146 | 0 | nsView * view; //used for call of get offset from view |
8147 | 0 | resultFrame->GetOffsetFromView(offset, &view); |
8148 | 0 | if (!view) { |
8149 | 0 | return NS_ERROR_FAILURE; |
8150 | 0 | } |
8151 | 0 | if (resultFrame->GetWritingMode().IsVertical()) { |
8152 | 0 | point.y = aPos->mDesiredPos.y; |
8153 | 0 | point.x = tempRect.width + offset.x; |
8154 | 0 | } else { |
8155 | 0 | point.y = tempRect.height + offset.y; |
8156 | 0 | point.x = aPos->mDesiredPos.x; |
8157 | 0 | } |
8158 | 0 |
|
8159 | 0 | //special check. if we allow non-text selection then we can allow a hit location to fall before a table. |
8160 | 0 | //otherwise there is no way to get and click signal to fall before a table (it being a line iterator itself) |
8161 | 0 | nsIPresShell *shell = aPresContext->GetPresShell(); |
8162 | 0 | if (!shell) |
8163 | 0 | return NS_ERROR_FAILURE; |
8164 | 0 | int16_t isEditor = shell->GetSelectionFlags(); |
8165 | 0 | isEditor = isEditor == nsISelectionDisplay::DISPLAY_ALL; |
8166 | 0 | if ( isEditor ) |
8167 | 0 | { |
8168 | 0 | if (resultFrame->IsTableWrapperFrame()) { |
8169 | 0 | if (((point.x - offset.x + tempRect.x)<0) || ((point.x - offset.x+ tempRect.x)>tempRect.width))//off left/right side |
8170 | 0 | { |
8171 | 0 | nsIContent* content = resultFrame->GetContent(); |
8172 | 0 | if (content) |
8173 | 0 | { |
8174 | 0 | nsIContent* parent = content->GetParent(); |
8175 | 0 | if (parent) |
8176 | 0 | { |
8177 | 0 | aPos->mResultContent = parent; |
8178 | 0 | aPos->mContentOffset = parent->ComputeIndexOf(content); |
8179 | 0 | aPos->mAttach = CARET_ASSOCIATE_BEFORE; |
8180 | 0 | if ((point.x - offset.x+ tempRect.x)>tempRect.width) |
8181 | 0 | { |
8182 | 0 | aPos->mContentOffset++;//go to end of this frame |
8183 | 0 | aPos->mAttach = CARET_ASSOCIATE_AFTER; |
8184 | 0 | } |
8185 | 0 | //result frame is the result frames parent. |
8186 | 0 | aPos->mResultFrame = resultFrame->GetParent(); |
8187 | 0 | return NS_POSITION_BEFORE_TABLE; |
8188 | 0 | } |
8189 | 0 | } |
8190 | 0 | } |
8191 | 0 | } |
8192 | 0 | } |
8193 | 0 |
|
8194 | 0 | if (!resultFrame->HasView()) |
8195 | 0 | { |
8196 | 0 | nsView* view; |
8197 | 0 | nsPoint offset; |
8198 | 0 | resultFrame->GetOffsetFromView(offset, &view); |
8199 | 0 | ContentOffsets offsets = |
8200 | 0 | resultFrame->GetContentOffsetsFromPoint(point - offset); |
8201 | 0 | aPos->mResultContent = offsets.content; |
8202 | 0 | aPos->mContentOffset = offsets.offset; |
8203 | 0 | aPos->mAttach = offsets.associate; |
8204 | 0 | if (offsets.content) |
8205 | 0 | { |
8206 | 0 | if (resultFrame->IsSelectable(nullptr)) { |
8207 | 0 | found = true; |
8208 | 0 | break; |
8209 | 0 | } |
8210 | 0 | } |
8211 | 0 | } |
8212 | 0 | |
8213 | 0 | if (aPos->mDirection == eDirPrevious && (resultFrame == farStoppingFrame)) |
8214 | 0 | break; |
8215 | 0 | if (aPos->mDirection == eDirNext && (resultFrame == nearStoppingFrame)) |
8216 | 0 | break; |
8217 | 0 | //always try previous on THAT line if that fails go the other way |
8218 | 0 | frameTraversal->Prev(); |
8219 | 0 | resultFrame = frameTraversal->CurrentItem(); |
8220 | 0 | if (!resultFrame) |
8221 | 0 | return NS_ERROR_FAILURE; |
8222 | 0 | } |
8223 | 0 |
|
8224 | 0 | if (!found){ |
8225 | 0 | resultFrame = storeOldResultFrame; |
8226 | 0 |
|
8227 | 0 | result = NS_NewFrameTraversal(getter_AddRefs(frameTraversal), |
8228 | 0 | aPresContext, resultFrame, |
8229 | 0 | eLeaf, |
8230 | 0 | false, // aVisual |
8231 | 0 | aPos->mScrollViewStop, |
8232 | 0 | false, // aFollowOOFs |
8233 | 0 | false // aSkipPopupChecks |
8234 | 0 | ); |
8235 | 0 | } |
8236 | 0 | while ( !found ){ |
8237 | 0 | nsPoint point = aPos->mDesiredPos; |
8238 | 0 | nsView* view; |
8239 | 0 | nsPoint offset; |
8240 | 0 | resultFrame->GetOffsetFromView(offset, &view); |
8241 | 0 | ContentOffsets offsets = |
8242 | 0 | resultFrame->GetContentOffsetsFromPoint(point - offset); |
8243 | 0 | aPos->mResultContent = offsets.content; |
8244 | 0 | aPos->mContentOffset = offsets.offset; |
8245 | 0 | aPos->mAttach = offsets.associate; |
8246 | 0 | if (offsets.content) |
8247 | 0 | { |
8248 | 0 | if (resultFrame->IsSelectable(nullptr)) { |
8249 | 0 | found = true; |
8250 | 0 | if (resultFrame == farStoppingFrame) |
8251 | 0 | aPos->mAttach = CARET_ASSOCIATE_BEFORE; |
8252 | 0 | else |
8253 | 0 | aPos->mAttach = CARET_ASSOCIATE_AFTER; |
8254 | 0 | break; |
8255 | 0 | } |
8256 | 0 | } |
8257 | 0 | if (aPos->mDirection == eDirPrevious && (resultFrame == nearStoppingFrame)) |
8258 | 0 | break; |
8259 | 0 | if (aPos->mDirection == eDirNext && (resultFrame == farStoppingFrame)) |
8260 | 0 | break; |
8261 | 0 | //previous didnt work now we try "next" |
8262 | 0 | frameTraversal->Next(); |
8263 | 0 | nsIFrame *tempFrame = frameTraversal->CurrentItem(); |
8264 | 0 | if (!tempFrame) |
8265 | 0 | break; |
8266 | 0 | resultFrame = tempFrame; |
8267 | 0 | } |
8268 | 0 | aPos->mResultFrame = resultFrame; |
8269 | 0 | } |
8270 | 0 | else { |
8271 | 0 | //we need to jump to new block frame. |
8272 | 0 | aPos->mAmount = eSelectLine; |
8273 | 0 | aPos->mStartOffset = 0; |
8274 | 0 | aPos->mAttach = aPos->mDirection == eDirNext ? |
8275 | 0 | CARET_ASSOCIATE_BEFORE : CARET_ASSOCIATE_AFTER; |
8276 | 0 | if (aPos->mDirection == eDirPrevious) |
8277 | 0 | aPos->mStartOffset = -1;//start from end |
8278 | 0 | return aBlockFrame->PeekOffset(aPos); |
8279 | 0 | } |
8280 | 0 | } |
8281 | 0 | return NS_OK; |
8282 | 0 | } |
8283 | | |
8284 | | nsIFrame::CaretPosition |
8285 | | nsIFrame::GetExtremeCaretPosition(bool aStart) |
8286 | 0 | { |
8287 | 0 | CaretPosition result; |
8288 | 0 |
|
8289 | 0 | FrameTarget targetFrame = DrillDownToSelectionFrame(this, !aStart, 0); |
8290 | 0 | FrameContentRange range = GetRangeForFrame(targetFrame.frame); |
8291 | 0 | result.mResultContent = range.content; |
8292 | 0 | result.mContentOffset = aStart ? range.start : range.end; |
8293 | 0 | return result; |
8294 | 0 | } |
8295 | | |
8296 | | // Find the first (or last) descendant of the given frame |
8297 | | // which is either a block frame or a BRFrame. |
8298 | | static nsContentAndOffset |
8299 | | FindBlockFrameOrBR(nsIFrame* aFrame, nsDirection aDirection) |
8300 | 0 | { |
8301 | 0 | nsContentAndOffset result; |
8302 | 0 | result.mContent = nullptr; |
8303 | 0 | result.mOffset = 0; |
8304 | 0 |
|
8305 | 0 | if (aFrame->IsGeneratedContentFrame()) |
8306 | 0 | return result; |
8307 | 0 | |
8308 | 0 | // Treat form controls as inline leaves |
8309 | 0 | // XXX we really need a way to determine whether a frame is inline-level |
8310 | 0 | nsIFormControlFrame* fcf = do_QueryFrame(aFrame); |
8311 | 0 | if (fcf) |
8312 | 0 | return result; |
8313 | 0 | |
8314 | 0 | // Check the frame itself |
8315 | 0 | // Fall through block-in-inline split frames because their mContent is |
8316 | 0 | // the content of the inline frames they were created from. The |
8317 | 0 | // first/last child of such frames is the real block frame we're |
8318 | 0 | // looking for. |
8319 | 0 | if ((nsLayoutUtils::GetAsBlock(aFrame) && |
8320 | 0 | !(aFrame->GetStateBits() & NS_FRAME_PART_OF_IBSPLIT)) || |
8321 | 0 | aFrame->IsBrFrame()) { |
8322 | 0 | nsIContent* content = aFrame->GetContent(); |
8323 | 0 | result.mContent = content->GetParent(); |
8324 | 0 | // In some cases (bug 310589, bug 370174) we end up here with a null content. |
8325 | 0 | // This probably shouldn't ever happen, but since it sometimes does, we want |
8326 | 0 | // to avoid crashing here. |
8327 | 0 | NS_ASSERTION(result.mContent, "Unexpected orphan content"); |
8328 | 0 | if (result.mContent) |
8329 | 0 | result.mOffset = result.mContent->ComputeIndexOf(content) + |
8330 | 0 | (aDirection == eDirPrevious ? 1 : 0); |
8331 | 0 | return result; |
8332 | 0 | } |
8333 | 0 |
|
8334 | 0 | // If this is a preformatted text frame, see if it ends with a newline |
8335 | 0 | if (aFrame->HasSignificantTerminalNewline()) { |
8336 | 0 | int32_t startOffset, endOffset; |
8337 | 0 | aFrame->GetOffsets(startOffset, endOffset); |
8338 | 0 | result.mContent = aFrame->GetContent(); |
8339 | 0 | result.mOffset = endOffset - (aDirection == eDirPrevious ? 0 : 1); |
8340 | 0 | return result; |
8341 | 0 | } |
8342 | 0 |
|
8343 | 0 | // Iterate over children and call ourselves recursively |
8344 | 0 | if (aDirection == eDirPrevious) { |
8345 | 0 | nsIFrame* child = aFrame->GetChildList(nsIFrame::kPrincipalList).LastChild(); |
8346 | 0 | while(child && !result.mContent) { |
8347 | 0 | result = FindBlockFrameOrBR(child, aDirection); |
8348 | 0 | child = child->GetPrevSibling(); |
8349 | 0 | } |
8350 | 0 | } else { // eDirNext |
8351 | 0 | nsIFrame* child = aFrame->PrincipalChildList().FirstChild(); |
8352 | 0 | while(child && !result.mContent) { |
8353 | 0 | result = FindBlockFrameOrBR(child, aDirection); |
8354 | 0 | child = child->GetNextSibling(); |
8355 | 0 | } |
8356 | 0 | } |
8357 | 0 | return result; |
8358 | 0 | } |
8359 | | |
8360 | | nsresult |
8361 | | nsIFrame::PeekOffsetParagraph(nsPeekOffsetStruct *aPos) |
8362 | 0 | { |
8363 | 0 | nsIFrame* frame = this; |
8364 | 0 | nsContentAndOffset blockFrameOrBR; |
8365 | 0 | blockFrameOrBR.mContent = nullptr; |
8366 | 0 | bool reachedBlockAncestor = !!nsLayoutUtils::GetAsBlock(frame); |
8367 | 0 |
|
8368 | 0 | // Go through containing frames until reaching a block frame. |
8369 | 0 | // In each step, search the previous (or next) siblings for the closest |
8370 | 0 | // "stop frame" (a block frame or a BRFrame). |
8371 | 0 | // If found, set it to be the selection boundray and abort. |
8372 | 0 |
|
8373 | 0 | if (aPos->mDirection == eDirPrevious) { |
8374 | 0 | while (!reachedBlockAncestor) { |
8375 | 0 | nsIFrame* parent = frame->GetParent(); |
8376 | 0 | // Treat a frame associated with the root content as if it were a block frame. |
8377 | 0 | if (!frame->mContent || !frame->mContent->GetParent()) { |
8378 | 0 | reachedBlockAncestor = true; |
8379 | 0 | break; |
8380 | 0 | } |
8381 | 0 | nsIFrame* sibling = frame->GetPrevSibling(); |
8382 | 0 | while (sibling && !blockFrameOrBR.mContent) { |
8383 | 0 | blockFrameOrBR = FindBlockFrameOrBR(sibling, eDirPrevious); |
8384 | 0 | sibling = sibling->GetPrevSibling(); |
8385 | 0 | } |
8386 | 0 | if (blockFrameOrBR.mContent) { |
8387 | 0 | aPos->mResultContent = blockFrameOrBR.mContent; |
8388 | 0 | aPos->mContentOffset = blockFrameOrBR.mOffset; |
8389 | 0 | break; |
8390 | 0 | } |
8391 | 0 | frame = parent; |
8392 | 0 | reachedBlockAncestor = (nsLayoutUtils::GetAsBlock(frame) != nullptr); |
8393 | 0 | } |
8394 | 0 | if (reachedBlockAncestor) { // no "stop frame" found |
8395 | 0 | aPos->mResultContent = frame->GetContent(); |
8396 | 0 | aPos->mContentOffset = 0; |
8397 | 0 | } |
8398 | 0 | } else { // eDirNext |
8399 | 0 | while (!reachedBlockAncestor) { |
8400 | 0 | nsIFrame* parent = frame->GetParent(); |
8401 | 0 | // Treat a frame associated with the root content as if it were a block frame. |
8402 | 0 | if (!frame->mContent || !frame->mContent->GetParent()) { |
8403 | 0 | reachedBlockAncestor = true; |
8404 | 0 | break; |
8405 | 0 | } |
8406 | 0 | nsIFrame* sibling = frame; |
8407 | 0 | while (sibling && !blockFrameOrBR.mContent) { |
8408 | 0 | blockFrameOrBR = FindBlockFrameOrBR(sibling, eDirNext); |
8409 | 0 | sibling = sibling->GetNextSibling(); |
8410 | 0 | } |
8411 | 0 | if (blockFrameOrBR.mContent) { |
8412 | 0 | aPos->mResultContent = blockFrameOrBR.mContent; |
8413 | 0 | aPos->mContentOffset = blockFrameOrBR.mOffset; |
8414 | 0 | break; |
8415 | 0 | } |
8416 | 0 | frame = parent; |
8417 | 0 | reachedBlockAncestor = !!nsLayoutUtils::GetAsBlock(frame); |
8418 | 0 | } |
8419 | 0 | if (reachedBlockAncestor) { // no "stop frame" found |
8420 | 0 | aPos->mResultContent = frame->GetContent(); |
8421 | 0 | if (aPos->mResultContent) |
8422 | 0 | aPos->mContentOffset = aPos->mResultContent->GetChildCount(); |
8423 | 0 | } |
8424 | 0 | } |
8425 | 0 | return NS_OK; |
8426 | 0 | } |
8427 | | |
8428 | | // Determine movement direction relative to frame |
8429 | | static bool IsMovingInFrameDirection(nsIFrame* frame, nsDirection aDirection, bool aVisual) |
8430 | 0 | { |
8431 | 0 | bool isReverseDirection = aVisual && IsReversedDirectionFrame(frame); |
8432 | 0 | return aDirection == (isReverseDirection ? eDirPrevious : eDirNext); |
8433 | 0 | } |
8434 | | |
8435 | | nsresult |
8436 | | nsIFrame::PeekOffset(nsPeekOffsetStruct* aPos) |
8437 | 0 | { |
8438 | 0 | if (!aPos) |
8439 | 0 | return NS_ERROR_NULL_POINTER; |
8440 | 0 | nsresult result = NS_ERROR_FAILURE; |
8441 | 0 |
|
8442 | 0 | if (mState & NS_FRAME_IS_DIRTY) |
8443 | 0 | return NS_ERROR_UNEXPECTED; |
8444 | 0 | |
8445 | 0 | // Translate content offset to be relative to frame |
8446 | 0 | FrameContentRange range = GetRangeForFrame(this); |
8447 | 0 | int32_t offset = aPos->mStartOffset - range.start; |
8448 | 0 | nsIFrame* current = this; |
8449 | 0 |
|
8450 | 0 | switch (aPos->mAmount) { |
8451 | 0 | case eSelectCharacter: |
8452 | 0 | case eSelectCluster: |
8453 | 0 | { |
8454 | 0 | bool eatingNonRenderableWS = false; |
8455 | 0 | nsIFrame::FrameSearchResult peekSearchState = CONTINUE; |
8456 | 0 | bool jumpedLine = false; |
8457 | 0 | bool movedOverNonSelectableText = false; |
8458 | 0 |
|
8459 | 0 | while (peekSearchState != FOUND) { |
8460 | 0 | bool movingInFrameDirection = |
8461 | 0 | IsMovingInFrameDirection(current, aPos->mDirection, aPos->mVisual); |
8462 | 0 |
|
8463 | 0 | if (eatingNonRenderableWS) { |
8464 | 0 | peekSearchState = current->PeekOffsetNoAmount(movingInFrameDirection, &offset); |
8465 | 0 | } else { |
8466 | 0 | PeekOffsetCharacterOptions options; |
8467 | 0 | options.mRespectClusters = aPos->mAmount == eSelectCluster; |
8468 | 0 | peekSearchState = current->PeekOffsetCharacter(movingInFrameDirection, |
8469 | 0 | &offset, options); |
8470 | 0 | } |
8471 | 0 |
|
8472 | 0 | movedOverNonSelectableText |= (peekSearchState == CONTINUE_UNSELECTABLE); |
8473 | 0 |
|
8474 | 0 | if (peekSearchState != FOUND) { |
8475 | 0 | bool movedOverNonSelectable = false; |
8476 | 0 | result = |
8477 | 0 | current->GetFrameFromDirection(aPos->mDirection, aPos->mVisual, |
8478 | 0 | aPos->mJumpLines, aPos->mScrollViewStop, |
8479 | 0 | ¤t, &offset, &jumpedLine, |
8480 | 0 | &movedOverNonSelectable); |
8481 | 0 | if (NS_FAILED(result)) |
8482 | 0 | return result; |
8483 | 0 | |
8484 | 0 | // If we jumped lines, it's as if we found a character, but we still need |
8485 | 0 | // to eat non-renderable content on the new line. |
8486 | 0 | if (jumpedLine) |
8487 | 0 | eatingNonRenderableWS = true; |
8488 | 0 |
|
8489 | 0 | // Remember if we moved over non-selectable text when finding another frame. |
8490 | 0 | if (movedOverNonSelectable) { |
8491 | 0 | movedOverNonSelectableText = true; |
8492 | 0 | } |
8493 | 0 | } |
8494 | 0 |
|
8495 | 0 | // Found frame, but because we moved over non selectable text we want the offset |
8496 | 0 | // to be at the frame edge. Note that if we are extending the selection, this |
8497 | 0 | // doesn't matter. |
8498 | 0 | if (peekSearchState == FOUND && movedOverNonSelectableText && |
8499 | 0 | !aPos->mExtend) |
8500 | 0 | { |
8501 | 0 | int32_t start, end; |
8502 | 0 | current->GetOffsets(start, end); |
8503 | 0 | offset = aPos->mDirection == eDirNext ? 0 : end - start; |
8504 | 0 | } |
8505 | 0 | } |
8506 | 0 |
|
8507 | 0 | // Set outputs |
8508 | 0 | range = GetRangeForFrame(current); |
8509 | 0 | aPos->mResultFrame = current; |
8510 | 0 | aPos->mResultContent = range.content; |
8511 | 0 | // Output offset is relative to content, not frame |
8512 | 0 | aPos->mContentOffset = offset < 0 ? range.end : range.start + offset; |
8513 | 0 | // If we're dealing with a text frame and moving backward positions us at |
8514 | 0 | // the end of that line, decrease the offset by one to make sure that |
8515 | 0 | // we're placed before the linefeed character on the previous line. |
8516 | 0 | if (offset < 0 && jumpedLine && |
8517 | 0 | aPos->mDirection == eDirPrevious && |
8518 | 0 | current->HasSignificantTerminalNewline()) { |
8519 | 0 | --aPos->mContentOffset; |
8520 | 0 | } |
8521 | 0 |
|
8522 | 0 | break; |
8523 | 0 | } |
8524 | 0 | case eSelectWordNoSpace: |
8525 | 0 | // eSelectWordNoSpace means that we should not be eating any whitespace when |
8526 | 0 | // moving to the adjacent word. This means that we should set aPos-> |
8527 | 0 | // mWordMovementType to eEndWord if we're moving forwards, and to eStartWord |
8528 | 0 | // if we're moving backwards. |
8529 | 0 | if (aPos->mDirection == eDirPrevious) { |
8530 | 0 | aPos->mWordMovementType = eStartWord; |
8531 | 0 | } else { |
8532 | 0 | aPos->mWordMovementType = eEndWord; |
8533 | 0 | } |
8534 | 0 | // Intentionally fall through the eSelectWord case. |
8535 | 0 | MOZ_FALLTHROUGH; |
8536 | 0 | case eSelectWord: |
8537 | 0 | { |
8538 | 0 | // wordSelectEatSpace means "are we looking for a boundary between whitespace |
8539 | 0 | // and non-whitespace (in the direction we're moving in)". |
8540 | 0 | // It is true when moving forward and looking for a beginning of a word, or |
8541 | 0 | // when moving backwards and looking for an end of a word. |
8542 | 0 | bool wordSelectEatSpace; |
8543 | 0 | if (aPos->mWordMovementType != eDefaultBehavior) { |
8544 | 0 | // aPos->mWordMovementType possible values: |
8545 | 0 | // eEndWord: eat the space if we're moving backwards |
8546 | 0 | // eStartWord: eat the space if we're moving forwards |
8547 | 0 | wordSelectEatSpace = ((aPos->mWordMovementType == eEndWord) == (aPos->mDirection == eDirPrevious)); |
8548 | 0 | } |
8549 | 0 | else { |
8550 | 0 | // Use the hidden preference which is based on operating system behavior. |
8551 | 0 | // This pref only affects whether moving forward by word should go to the end of this word or start of the next word. |
8552 | 0 | // When going backwards, the start of the word is always used, on every operating system. |
8553 | 0 | wordSelectEatSpace = aPos->mDirection == eDirNext && |
8554 | 0 | Preferences::GetBool("layout.word_select.eat_space_to_next_word"); |
8555 | 0 | } |
8556 | 0 |
|
8557 | 0 | // mSawBeforeType means "we already saw characters of the type |
8558 | 0 | // before the boundary we're looking for". Examples: |
8559 | 0 | // 1. If we're moving forward, looking for a word beginning (i.e. a boundary |
8560 | 0 | // between whitespace and non-whitespace), then eatingWS==true means |
8561 | 0 | // "we already saw some whitespace". |
8562 | 0 | // 2. If we're moving backward, looking for a word beginning (i.e. a boundary |
8563 | 0 | // between non-whitespace and whitespace), then eatingWS==true means |
8564 | 0 | // "we already saw some non-whitespace". |
8565 | 0 | PeekWordState state; |
8566 | 0 | int32_t offsetAdjustment = 0; |
8567 | 0 | bool done = false; |
8568 | 0 | while (!done) { |
8569 | 0 | bool movingInFrameDirection = |
8570 | 0 | IsMovingInFrameDirection(current, aPos->mDirection, aPos->mVisual); |
8571 | 0 |
|
8572 | 0 | done = current->PeekOffsetWord(movingInFrameDirection, wordSelectEatSpace, |
8573 | 0 | aPos->mIsKeyboardSelect, &offset, &state) == FOUND; |
8574 | 0 |
|
8575 | 0 | if (!done) { |
8576 | 0 | nsIFrame* nextFrame; |
8577 | 0 | int32_t nextFrameOffset; |
8578 | 0 | bool jumpedLine, movedOverNonSelectableText; |
8579 | 0 | result = |
8580 | 0 | current->GetFrameFromDirection(aPos->mDirection, aPos->mVisual, |
8581 | 0 | aPos->mJumpLines, aPos->mScrollViewStop, |
8582 | 0 | &nextFrame, &nextFrameOffset, &jumpedLine, |
8583 | 0 | &movedOverNonSelectableText); |
8584 | 0 | // We can't jump lines if we're looking for whitespace following |
8585 | 0 | // non-whitespace, and we already encountered non-whitespace. |
8586 | 0 | if (NS_FAILED(result) || |
8587 | 0 | (jumpedLine && !wordSelectEatSpace && state.mSawBeforeType)) { |
8588 | 0 | done = true; |
8589 | 0 | // If we've crossed the line boundary, check to make sure that we |
8590 | 0 | // have not consumed a trailing newline as whitesapce if it's significant. |
8591 | 0 | if (jumpedLine && wordSelectEatSpace && |
8592 | 0 | current->HasSignificantTerminalNewline()) { |
8593 | 0 | offsetAdjustment = -1; |
8594 | 0 | } |
8595 | 0 | } else { |
8596 | 0 | if (jumpedLine) { |
8597 | 0 | state.mContext.Truncate(); |
8598 | 0 | } |
8599 | 0 | current = nextFrame; |
8600 | 0 | offset = nextFrameOffset; |
8601 | 0 | // Jumping a line is equivalent to encountering whitespace |
8602 | 0 | if (wordSelectEatSpace && jumpedLine) |
8603 | 0 | state.SetSawBeforeType(); |
8604 | 0 | } |
8605 | 0 | } |
8606 | 0 | } |
8607 | 0 |
|
8608 | 0 | // Set outputs |
8609 | 0 | range = GetRangeForFrame(current); |
8610 | 0 | aPos->mResultFrame = current; |
8611 | 0 | aPos->mResultContent = range.content; |
8612 | 0 | // Output offset is relative to content, not frame |
8613 | 0 | aPos->mContentOffset = (offset < 0 ? range.end : range.start + offset) + offsetAdjustment; |
8614 | 0 | break; |
8615 | 0 | } |
8616 | 0 | case eSelectLine : |
8617 | 0 | { |
8618 | 0 | nsAutoLineIterator iter; |
8619 | 0 | nsIFrame *blockFrame = this; |
8620 | 0 |
|
8621 | 0 | while (NS_FAILED(result)){ |
8622 | 0 | int32_t thisLine = nsFrame::GetLineNumber(blockFrame, aPos->mScrollViewStop, &blockFrame); |
8623 | 0 | if (thisLine < 0) |
8624 | 0 | return NS_ERROR_FAILURE; |
8625 | 0 | iter = blockFrame->GetLineIterator(); |
8626 | 0 | NS_ASSERTION(iter, "GetLineNumber() succeeded but no block frame?"); |
8627 | 0 | result = NS_OK; |
8628 | 0 |
|
8629 | 0 | int edgeCase = 0; // no edge case. this should look at thisLine |
8630 | 0 |
|
8631 | 0 | bool doneLooping = false; // tells us when no more block frames hit. |
8632 | 0 | // this part will find a frame or a block frame. if it's a block frame |
8633 | 0 | // it will "drill down" to find a viable frame or it will return an error. |
8634 | 0 | nsIFrame *lastFrame = this; |
8635 | 0 | do { |
8636 | 0 | result = nsFrame::GetNextPrevLineFromeBlockFrame(PresContext(), |
8637 | 0 | aPos, |
8638 | 0 | blockFrame, |
8639 | 0 | thisLine, |
8640 | 0 | edgeCase); // start from thisLine |
8641 | 0 |
|
8642 | 0 | // we came back to same spot! keep going |
8643 | 0 | if (NS_SUCCEEDED(result) && |
8644 | 0 | (!aPos->mResultFrame || aPos->mResultFrame == lastFrame)) { |
8645 | 0 | aPos->mResultFrame = nullptr; |
8646 | 0 | if (aPos->mDirection == eDirPrevious) |
8647 | 0 | thisLine--; |
8648 | 0 | else |
8649 | 0 | thisLine++; |
8650 | 0 | } else // if failure or success with different frame. |
8651 | 0 | doneLooping = true; // do not continue with while loop |
8652 | 0 |
|
8653 | 0 | lastFrame = aPos->mResultFrame; // set last frame |
8654 | 0 |
|
8655 | 0 | // make sure block element is not the same as the one we had before |
8656 | 0 | if (NS_SUCCEEDED(result) && |
8657 | 0 | aPos->mResultFrame && |
8658 | 0 | blockFrame != aPos->mResultFrame) { |
8659 | 0 | /* SPECIAL CHECK FOR TABLE NAVIGATION |
8660 | 0 | tables need to navigate also and the frame that supports it is |
8661 | 0 | nsTableRowGroupFrame which is INSIDE nsTableWrapperFrame. |
8662 | 0 | If we have stumbled onto an nsTableWrapperFrame we need to drill |
8663 | 0 | into nsTableRowGroup if we hit a header or footer that's ok just |
8664 | 0 | go into them. |
8665 | 0 | */ |
8666 | 0 | bool searchTableBool = false; |
8667 | 0 | if (aPos->mResultFrame->IsTableWrapperFrame() || |
8668 | 0 | aPos->mResultFrame->IsTableCellFrame()) { |
8669 | 0 | nsIFrame* frame = aPos->mResultFrame->PrincipalChildList().FirstChild(); |
8670 | 0 | // got the table frame now |
8671 | 0 | // ok time to drill down to find iterator |
8672 | 0 | while (frame) { |
8673 | 0 | iter = frame->GetLineIterator(); |
8674 | 0 | if (iter) { |
8675 | 0 | aPos->mResultFrame = frame; |
8676 | 0 | searchTableBool = true; |
8677 | 0 | result = NS_OK; |
8678 | 0 | break; // while(frame) |
8679 | 0 | } |
8680 | 0 | result = NS_ERROR_FAILURE; |
8681 | 0 | frame = frame->PrincipalChildList().FirstChild(); |
8682 | 0 | } |
8683 | 0 | } |
8684 | 0 |
|
8685 | 0 | if (!searchTableBool) { |
8686 | 0 | iter = aPos->mResultFrame->GetLineIterator(); |
8687 | 0 | result = iter ? NS_OK : NS_ERROR_FAILURE; |
8688 | 0 | } |
8689 | 0 |
|
8690 | 0 | // we've struck another block element! |
8691 | 0 | if (NS_SUCCEEDED(result) && iter) { |
8692 | 0 | doneLooping = false; |
8693 | 0 | if (aPos->mDirection == eDirPrevious) |
8694 | 0 | edgeCase = 1; // far edge, search from end backwards |
8695 | 0 | else |
8696 | 0 | edgeCase = -1; // near edge search from beginning onwards |
8697 | 0 | thisLine = 0; // this line means nothing now. |
8698 | 0 | // everything else means something so keep looking "inside" the block |
8699 | 0 | blockFrame = aPos->mResultFrame; |
8700 | 0 | } else { |
8701 | 0 | // THIS is to mean that everything is ok to the containing while loop |
8702 | 0 | result = NS_OK; |
8703 | 0 | break; |
8704 | 0 | } |
8705 | 0 | } |
8706 | 0 | } while (!doneLooping); |
8707 | 0 | } |
8708 | 0 | return result; |
8709 | 0 | } |
8710 | 0 |
|
8711 | 0 | case eSelectParagraph: |
8712 | 0 | return PeekOffsetParagraph(aPos); |
8713 | 0 |
|
8714 | 0 | case eSelectBeginLine: |
8715 | 0 | case eSelectEndLine: |
8716 | 0 | { |
8717 | 0 | // Adjusted so that the caret can't get confused when content changes |
8718 | 0 | nsIFrame* blockFrame = AdjustFrameForSelectionStyles(this); |
8719 | 0 | int32_t thisLine = nsFrame::GetLineNumber(blockFrame, aPos->mScrollViewStop, &blockFrame); |
8720 | 0 | if (thisLine < 0) |
8721 | 0 | return NS_ERROR_FAILURE; |
8722 | 0 | nsAutoLineIterator it = blockFrame->GetLineIterator(); |
8723 | 0 | NS_ASSERTION(it, "GetLineNumber() succeeded but no block frame?"); |
8724 | 0 |
|
8725 | 0 | int32_t lineFrameCount; |
8726 | 0 | nsIFrame *firstFrame; |
8727 | 0 | nsRect usedRect; |
8728 | 0 | nsIFrame* baseFrame = nullptr; |
8729 | 0 | bool endOfLine = (eSelectEndLine == aPos->mAmount); |
8730 | 0 |
|
8731 | 0 | if (aPos->mVisual && PresContext()->BidiEnabled()) { |
8732 | 0 | bool lineIsRTL = it->GetDirection(); |
8733 | 0 | bool isReordered; |
8734 | 0 | nsIFrame *lastFrame; |
8735 | 0 | result = it->CheckLineOrder(thisLine, &isReordered, &firstFrame, &lastFrame); |
8736 | 0 | baseFrame = endOfLine ? lastFrame : firstFrame; |
8737 | 0 | if (baseFrame) { |
8738 | 0 | bool frameIsRTL = |
8739 | 0 | (nsBidiPresUtils::FrameDirection(baseFrame) == NSBIDI_RTL); |
8740 | 0 | // If the direction of the frame on the edge is opposite to |
8741 | 0 | // that of the line, we'll need to drill down to its opposite |
8742 | 0 | // end, so reverse endOfLine. |
8743 | 0 | if (frameIsRTL != lineIsRTL) { |
8744 | 0 | endOfLine = !endOfLine; |
8745 | 0 | } |
8746 | 0 | } |
8747 | 0 | } else { |
8748 | 0 | it->GetLine(thisLine, &firstFrame, &lineFrameCount, usedRect); |
8749 | 0 |
|
8750 | 0 | nsIFrame* frame = firstFrame; |
8751 | 0 | for (int32_t count = lineFrameCount; count; |
8752 | 0 | --count, frame = frame->GetNextSibling()) { |
8753 | 0 | if (!frame->IsGeneratedContentFrame()) { |
8754 | 0 | // When jumping to the end of the line with the "end" key, |
8755 | 0 | // skip over brFrames |
8756 | 0 | if (endOfLine && lineFrameCount > 1 && frame->IsBrFrame()) { |
8757 | 0 | continue; |
8758 | 0 | } |
8759 | 0 | baseFrame = frame; |
8760 | 0 | if (!endOfLine) |
8761 | 0 | break; |
8762 | 0 | } |
8763 | 0 | } |
8764 | 0 | } |
8765 | 0 | if (!baseFrame) |
8766 | 0 | return NS_ERROR_FAILURE; |
8767 | 0 | FrameTarget targetFrame = DrillDownToSelectionFrame(baseFrame, |
8768 | 0 | endOfLine, 0); |
8769 | 0 | FrameContentRange range = GetRangeForFrame(targetFrame.frame); |
8770 | 0 | aPos->mResultContent = range.content; |
8771 | 0 | aPos->mContentOffset = endOfLine ? range.end : range.start; |
8772 | 0 | if (endOfLine && targetFrame.frame->HasSignificantTerminalNewline()) { |
8773 | 0 | // Do not position the caret after the terminating newline if we're |
8774 | 0 | // trying to move to the end of line (see bug 596506) |
8775 | 0 | --aPos->mContentOffset; |
8776 | 0 | } |
8777 | 0 | aPos->mResultFrame = targetFrame.frame; |
8778 | 0 | aPos->mAttach = aPos->mContentOffset == range.start ? |
8779 | 0 | CARET_ASSOCIATE_AFTER : CARET_ASSOCIATE_BEFORE; |
8780 | 0 | if (!range.content) |
8781 | 0 | return NS_ERROR_FAILURE; |
8782 | 0 | return NS_OK; |
8783 | 0 | } |
8784 | 0 |
|
8785 | 0 | default: |
8786 | 0 | { |
8787 | 0 | NS_ASSERTION(false, "Invalid amount"); |
8788 | 0 | return NS_ERROR_FAILURE; |
8789 | 0 | } |
8790 | 0 | } |
8791 | 0 | return NS_OK; |
8792 | 0 | } |
8793 | | |
8794 | | nsIFrame::FrameSearchResult |
8795 | | nsFrame::PeekOffsetNoAmount(bool aForward, int32_t* aOffset) |
8796 | 0 | { |
8797 | 0 | NS_ASSERTION (aOffset && *aOffset <= 1, "aOffset out of range"); |
8798 | 0 | // Sure, we can stop right here. |
8799 | 0 | return FOUND; |
8800 | 0 | } |
8801 | | |
8802 | | nsIFrame::FrameSearchResult |
8803 | | nsFrame::PeekOffsetCharacter(bool aForward, int32_t* aOffset, |
8804 | | PeekOffsetCharacterOptions aOptions) |
8805 | 0 | { |
8806 | 0 | NS_ASSERTION (aOffset && *aOffset <= 1, "aOffset out of range"); |
8807 | 0 | int32_t startOffset = *aOffset; |
8808 | 0 | // A negative offset means "end of frame", which in our case means offset 1. |
8809 | 0 | if (startOffset < 0) |
8810 | 0 | startOffset = 1; |
8811 | 0 | if (aForward == (startOffset == 0)) { |
8812 | 0 | // We're before the frame and moving forward, or after it and moving backwards: |
8813 | 0 | // skip to the other side and we're done. |
8814 | 0 | *aOffset = 1 - startOffset; |
8815 | 0 | return FOUND; |
8816 | 0 | } |
8817 | 0 | return CONTINUE; |
8818 | 0 | } |
8819 | | |
8820 | | nsIFrame::FrameSearchResult |
8821 | | nsFrame::PeekOffsetWord(bool aForward, |
8822 | | bool aWordSelectEatSpace, |
8823 | | bool aIsKeyboardSelect, |
8824 | | int32_t* aOffset, |
8825 | | PeekWordState* aState) |
8826 | 0 | { |
8827 | 0 | NS_ASSERTION (aOffset && *aOffset <= 1, "aOffset out of range"); |
8828 | 0 | int32_t startOffset = *aOffset; |
8829 | 0 | // This isn't text, so truncate the context |
8830 | 0 | aState->mContext.Truncate(); |
8831 | 0 | if (startOffset < 0) |
8832 | 0 | startOffset = 1; |
8833 | 0 | if (aForward == (startOffset == 0)) { |
8834 | 0 | // We're before the frame and moving forward, or after it and moving backwards. |
8835 | 0 | // If we're looking for non-whitespace, we found it (without skipping this frame). |
8836 | 0 | if (!aState->mAtStart) { |
8837 | 0 | if (aState->mLastCharWasPunctuation) { |
8838 | 0 | // We're not punctuation, so this is a punctuation boundary. |
8839 | 0 | if (BreakWordBetweenPunctuation(aState, aForward, false, false, aIsKeyboardSelect)) |
8840 | 0 | return FOUND; |
8841 | 0 | } else { |
8842 | 0 | // This is not a punctuation boundary. |
8843 | 0 | if (aWordSelectEatSpace && aState->mSawBeforeType) |
8844 | 0 | return FOUND; |
8845 | 0 | } |
8846 | 0 | } |
8847 | 0 | // Otherwise skip to the other side and note that we encountered non-whitespace. |
8848 | 0 | *aOffset = 1 - startOffset; |
8849 | 0 | aState->Update(false, // not punctuation |
8850 | 0 | false // not whitespace |
8851 | 0 | ); |
8852 | 0 | if (!aWordSelectEatSpace) |
8853 | 0 | aState->SetSawBeforeType(); |
8854 | 0 | } |
8855 | 0 | return CONTINUE; |
8856 | 0 | } |
8857 | | |
8858 | | bool |
8859 | | nsFrame::BreakWordBetweenPunctuation(const PeekWordState* aState, |
8860 | | bool aForward, |
8861 | | bool aPunctAfter, bool aWhitespaceAfter, |
8862 | | bool aIsKeyboardSelect) |
8863 | 0 | { |
8864 | 0 | NS_ASSERTION(aPunctAfter != aState->mLastCharWasPunctuation, |
8865 | 0 | "Call this only at punctuation boundaries"); |
8866 | 0 | if (aState->mLastCharWasWhitespace) { |
8867 | 0 | // We always stop between whitespace and punctuation |
8868 | 0 | return true; |
8869 | 0 | } |
8870 | 0 | if (!Preferences::GetBool("layout.word_select.stop_at_punctuation")) { |
8871 | 0 | // When this pref is false, we never stop at a punctuation boundary unless |
8872 | 0 | // it's followed by whitespace (in the relevant direction). |
8873 | 0 | return aWhitespaceAfter; |
8874 | 0 | } |
8875 | 0 | if (!aIsKeyboardSelect) { |
8876 | 0 | // mouse caret movement (e.g. word selection) always stops at every punctuation boundary |
8877 | 0 | return true; |
8878 | 0 | } |
8879 | 0 | bool afterPunct = aForward ? aState->mLastCharWasPunctuation : aPunctAfter; |
8880 | 0 | if (!afterPunct) { |
8881 | 0 | // keyboard caret movement only stops after punctuation (in content order) |
8882 | 0 | return false; |
8883 | 0 | } |
8884 | 0 | // Stop only if we've seen some non-punctuation since the last whitespace; |
8885 | 0 | // don't stop after punctuation that follows whitespace. |
8886 | 0 | return aState->mSeenNonPunctuationSinceWhitespace; |
8887 | 0 | } |
8888 | | |
8889 | | nsresult |
8890 | | nsFrame::CheckVisibility(nsPresContext* , int32_t , int32_t , bool , bool *, bool *) |
8891 | 0 | { |
8892 | 0 | return NS_ERROR_NOT_IMPLEMENTED; |
8893 | 0 | } |
8894 | | |
8895 | | |
8896 | | int32_t |
8897 | | nsFrame::GetLineNumber(nsIFrame *aFrame, bool aLockScroll, nsIFrame** aContainingBlock) |
8898 | 0 | { |
8899 | 0 | NS_ASSERTION(aFrame, "null aFrame"); |
8900 | 0 | nsIFrame* blockFrame = aFrame; |
8901 | 0 | nsIFrame* thisBlock; |
8902 | 0 | nsAutoLineIterator it; |
8903 | 0 | nsresult result = NS_ERROR_FAILURE; |
8904 | 0 | while (NS_FAILED(result) && blockFrame) |
8905 | 0 | { |
8906 | 0 | thisBlock = blockFrame; |
8907 | 0 | if (thisBlock->GetStateBits() & NS_FRAME_OUT_OF_FLOW) { |
8908 | 0 | //if we are searching for a frame that is not in flow we will not find it. |
8909 | 0 | //we must instead look for its placeholder |
8910 | 0 | if (thisBlock->GetStateBits() & NS_FRAME_IS_OVERFLOW_CONTAINER) { |
8911 | 0 | // abspos continuations don't have placeholders, get the fif |
8912 | 0 | thisBlock = thisBlock->FirstInFlow(); |
8913 | 0 | } |
8914 | 0 | thisBlock = thisBlock->GetPlaceholderFrame(); |
8915 | 0 | if (!thisBlock) |
8916 | 0 | return -1; |
8917 | 0 | } |
8918 | 0 | blockFrame = thisBlock->GetParent(); |
8919 | 0 | result = NS_OK; |
8920 | 0 | if (blockFrame) { |
8921 | 0 | if (aLockScroll && blockFrame->IsScrollFrame()) |
8922 | 0 | return -1; |
8923 | 0 | it = blockFrame->GetLineIterator(); |
8924 | 0 | if (!it) |
8925 | 0 | result = NS_ERROR_FAILURE; |
8926 | 0 | } |
8927 | 0 | } |
8928 | 0 | if (!blockFrame || !it) |
8929 | 0 | return -1; |
8930 | 0 | |
8931 | 0 | if (aContainingBlock) |
8932 | 0 | *aContainingBlock = blockFrame; |
8933 | 0 | return it->FindLineContaining(thisBlock); |
8934 | 0 | } |
8935 | | |
8936 | | nsresult |
8937 | | nsIFrame::GetFrameFromDirection(nsDirection aDirection, bool aVisual, |
8938 | | bool aJumpLines, bool aScrollViewStop, |
8939 | | nsIFrame** aOutFrame, int32_t* aOutOffset, |
8940 | | bool* aOutJumpedLine, bool* aOutMovedOverNonSelectableText) |
8941 | 0 | { |
8942 | 0 | nsresult result; |
8943 | 0 |
|
8944 | 0 | if (!aOutFrame || !aOutOffset || !aOutJumpedLine) |
8945 | 0 | return NS_ERROR_NULL_POINTER; |
8946 | 0 | |
8947 | 0 | nsPresContext* presContext = PresContext(); |
8948 | 0 | *aOutFrame = nullptr; |
8949 | 0 | *aOutOffset = 0; |
8950 | 0 | *aOutJumpedLine = false; |
8951 | 0 | *aOutMovedOverNonSelectableText = false; |
8952 | 0 |
|
8953 | 0 | // Find the prev/next selectable frame |
8954 | 0 | bool selectable = false; |
8955 | 0 | nsIFrame *traversedFrame = this; |
8956 | 0 | while (!selectable) { |
8957 | 0 | nsIFrame *blockFrame; |
8958 | 0 |
|
8959 | 0 | int32_t thisLine = nsFrame::GetLineNumber(traversedFrame, aScrollViewStop, &blockFrame); |
8960 | 0 | if (thisLine < 0) |
8961 | 0 | return NS_ERROR_FAILURE; |
8962 | 0 | |
8963 | 0 | nsAutoLineIterator it = blockFrame->GetLineIterator(); |
8964 | 0 | NS_ASSERTION(it, "GetLineNumber() succeeded but no block frame?"); |
8965 | 0 |
|
8966 | 0 | bool atLineEdge; |
8967 | 0 | nsIFrame *firstFrame; |
8968 | 0 | nsIFrame *lastFrame; |
8969 | 0 | if (aVisual && presContext->BidiEnabled()) { |
8970 | 0 | bool lineIsRTL = it->GetDirection(); |
8971 | 0 | bool isReordered; |
8972 | 0 | result = it->CheckLineOrder(thisLine, &isReordered, &firstFrame, &lastFrame); |
8973 | 0 | nsIFrame** framePtr = aDirection == eDirPrevious ? &firstFrame : &lastFrame; |
8974 | 0 | if (*framePtr) { |
8975 | 0 | bool frameIsRTL = |
8976 | 0 | (nsBidiPresUtils::FrameDirection(*framePtr) == NSBIDI_RTL); |
8977 | 0 | if ((frameIsRTL == lineIsRTL) == (aDirection == eDirPrevious)) { |
8978 | 0 | nsFrame::GetFirstLeaf(presContext, framePtr); |
8979 | 0 | } else { |
8980 | 0 | nsFrame::GetLastLeaf(presContext, framePtr); |
8981 | 0 | } |
8982 | 0 | atLineEdge = *framePtr == traversedFrame; |
8983 | 0 | } else { |
8984 | 0 | atLineEdge = true; |
8985 | 0 | } |
8986 | 0 | } else { |
8987 | 0 | nsRect nonUsedRect; |
8988 | 0 | int32_t lineFrameCount; |
8989 | 0 | result = it->GetLine(thisLine, &firstFrame, &lineFrameCount, |
8990 | 0 | nonUsedRect); |
8991 | 0 | if (NS_FAILED(result)) |
8992 | 0 | return result; |
8993 | 0 | |
8994 | 0 | if (aDirection == eDirPrevious) { |
8995 | 0 | nsFrame::GetFirstLeaf(presContext, &firstFrame); |
8996 | 0 | atLineEdge = firstFrame == traversedFrame; |
8997 | 0 | } else { // eDirNext |
8998 | 0 | lastFrame = firstFrame; |
8999 | 0 | for (;lineFrameCount > 1;lineFrameCount --){ |
9000 | 0 | result = it->GetNextSiblingOnLine(lastFrame, thisLine); |
9001 | 0 | if (NS_FAILED(result) || !lastFrame){ |
9002 | 0 | NS_ERROR("should not be reached nsFrame"); |
9003 | 0 | return NS_ERROR_FAILURE; |
9004 | 0 | } |
9005 | 0 | } |
9006 | 0 | nsFrame::GetLastLeaf(presContext, &lastFrame); |
9007 | 0 | atLineEdge = lastFrame == traversedFrame; |
9008 | 0 | } |
9009 | 0 | } |
9010 | 0 |
|
9011 | 0 | if (atLineEdge) { |
9012 | 0 | *aOutJumpedLine = true; |
9013 | 0 | if (!aJumpLines) |
9014 | 0 | return NS_ERROR_FAILURE; //we are done. cannot jump lines |
9015 | 0 | } |
9016 | 0 | |
9017 | 0 | nsCOMPtr<nsIFrameEnumerator> frameTraversal; |
9018 | 0 | result = NS_NewFrameTraversal(getter_AddRefs(frameTraversal), |
9019 | 0 | presContext, traversedFrame, |
9020 | 0 | eLeaf, |
9021 | 0 | aVisual && presContext->BidiEnabled(), |
9022 | 0 | aScrollViewStop, |
9023 | 0 | true, // aFollowOOFs |
9024 | 0 | false // aSkipPopupChecks |
9025 | 0 | ); |
9026 | 0 | if (NS_FAILED(result)) |
9027 | 0 | return result; |
9028 | 0 | |
9029 | 0 | if (aDirection == eDirNext) |
9030 | 0 | frameTraversal->Next(); |
9031 | 0 | else |
9032 | 0 | frameTraversal->Prev(); |
9033 | 0 |
|
9034 | 0 | traversedFrame = frameTraversal->CurrentItem(); |
9035 | 0 |
|
9036 | 0 | // Skip anonymous elements, but watch out for generated content |
9037 | 0 | if (!traversedFrame || |
9038 | 0 | (!traversedFrame->IsGeneratedContentFrame() && |
9039 | 0 | traversedFrame->GetContent()->IsRootOfNativeAnonymousSubtree())) { |
9040 | 0 | return NS_ERROR_FAILURE; |
9041 | 0 | } |
9042 | 0 | |
9043 | 0 | // Skip brFrames, but only if they are not the only frame in the line |
9044 | 0 | if (atLineEdge && aDirection == eDirPrevious && |
9045 | 0 | traversedFrame->IsBrFrame()) { |
9046 | 0 | int32_t lineFrameCount; |
9047 | 0 | nsIFrame *currentBlockFrame, *currentFirstFrame; |
9048 | 0 | nsRect usedRect; |
9049 | 0 | int32_t currentLine = nsFrame::GetLineNumber(traversedFrame, aScrollViewStop, ¤tBlockFrame); |
9050 | 0 | nsAutoLineIterator iter = currentBlockFrame->GetLineIterator(); |
9051 | 0 | result = iter->GetLine(currentLine, ¤tFirstFrame, &lineFrameCount, usedRect); |
9052 | 0 | if (NS_FAILED(result)) { |
9053 | 0 | return result; |
9054 | 0 | } |
9055 | 0 | if (lineFrameCount > 1) { |
9056 | 0 | continue; |
9057 | 0 | } |
9058 | 0 | } |
9059 | 0 | |
9060 | 0 | selectable = traversedFrame->IsSelectable(nullptr); |
9061 | 0 | if (!selectable) { |
9062 | 0 | *aOutMovedOverNonSelectableText = true; |
9063 | 0 | } |
9064 | 0 | } // while (!selectable) |
9065 | 0 |
|
9066 | 0 | *aOutOffset = (aDirection == eDirNext) ? 0 : -1; |
9067 | 0 |
|
9068 | 0 | if (aVisual && IsReversedDirectionFrame(traversedFrame)) { |
9069 | 0 | // The new frame is reverse-direction, go to the other end |
9070 | 0 | *aOutOffset = -1 - *aOutOffset; |
9071 | 0 | } |
9072 | 0 | *aOutFrame = traversedFrame; |
9073 | 0 | return NS_OK; |
9074 | 0 | } |
9075 | | |
9076 | | nsView* nsIFrame::GetClosestView(nsPoint* aOffset) const |
9077 | 0 | { |
9078 | 0 | nsPoint offset(0,0); |
9079 | 0 | for (const nsIFrame *f = this; f; f = f->GetParent()) { |
9080 | 0 | if (f->HasView()) { |
9081 | 0 | if (aOffset) |
9082 | 0 | *aOffset = offset; |
9083 | 0 | return f->GetView(); |
9084 | 0 | } |
9085 | 0 | offset += f->GetPosition(); |
9086 | 0 | } |
9087 | 0 |
|
9088 | 0 | MOZ_ASSERT_UNREACHABLE("No view on any parent? How did that happen?"); |
9089 | 0 | return nullptr; |
9090 | 0 | } |
9091 | | |
9092 | | |
9093 | | /* virtual */ void |
9094 | | nsFrame::ChildIsDirty(nsIFrame* aChild) |
9095 | 0 | { |
9096 | 0 | MOZ_ASSERT_UNREACHABLE("should never be called on a frame that doesn't " |
9097 | 0 | "inherit from nsContainerFrame"); |
9098 | 0 | } |
9099 | | |
9100 | | |
9101 | | #ifdef ACCESSIBILITY |
9102 | | a11y::AccType |
9103 | | nsFrame::AccessibleType() |
9104 | 0 | { |
9105 | 0 | if (IsTableCaption() && !GetRect().IsEmpty()) { |
9106 | 0 | return a11y::eHTMLCaptionType; |
9107 | 0 | } |
9108 | 0 | return a11y::eNoType; |
9109 | 0 | } |
9110 | | #endif |
9111 | | |
9112 | | bool |
9113 | | nsIFrame::ClearOverflowRects() |
9114 | 0 | { |
9115 | 0 | if (mOverflow.mType == NS_FRAME_OVERFLOW_NONE) { |
9116 | 0 | return false; |
9117 | 0 | } |
9118 | 0 | if (mOverflow.mType == NS_FRAME_OVERFLOW_LARGE) { |
9119 | 0 | DeleteProperty(OverflowAreasProperty()); |
9120 | 0 | } |
9121 | 0 | mOverflow.mType = NS_FRAME_OVERFLOW_NONE; |
9122 | 0 | return true; |
9123 | 0 | } |
9124 | | |
9125 | | /** Set the overflowArea rect, storing it as deltas or a separate rect |
9126 | | * depending on its size in relation to the primary frame rect. |
9127 | | */ |
9128 | | bool |
9129 | | nsIFrame::SetOverflowAreas(const nsOverflowAreas& aOverflowAreas) |
9130 | 0 | { |
9131 | 0 | if (mOverflow.mType == NS_FRAME_OVERFLOW_LARGE) { |
9132 | 0 | nsOverflowAreas* overflow = GetOverflowAreasProperty(); |
9133 | 0 | bool changed = *overflow != aOverflowAreas; |
9134 | 0 | *overflow = aOverflowAreas; |
9135 | 0 |
|
9136 | 0 | // Don't bother with converting to the deltas form if we already |
9137 | 0 | // have a property. |
9138 | 0 | return changed; |
9139 | 0 | } |
9140 | 0 | |
9141 | 0 | const nsRect& vis = aOverflowAreas.VisualOverflow(); |
9142 | 0 | uint32_t l = -vis.x, // left edge: positive delta is leftwards |
9143 | 0 | t = -vis.y, // top: positive is upwards |
9144 | 0 | r = vis.XMost() - mRect.width, // right: positive is rightwards |
9145 | 0 | b = vis.YMost() - mRect.height; // bottom: positive is downwards |
9146 | 0 | if (aOverflowAreas.ScrollableOverflow().IsEqualEdges(nsRect(nsPoint(0, 0), GetSize())) && |
9147 | 0 | l <= NS_FRAME_OVERFLOW_DELTA_MAX && |
9148 | 0 | t <= NS_FRAME_OVERFLOW_DELTA_MAX && |
9149 | 0 | r <= NS_FRAME_OVERFLOW_DELTA_MAX && |
9150 | 0 | b <= NS_FRAME_OVERFLOW_DELTA_MAX && |
9151 | 0 | // we have to check these against zero because we *never* want to |
9152 | 0 | // set a frame as having no overflow in this function. This is |
9153 | 0 | // because FinishAndStoreOverflow calls this function prior to |
9154 | 0 | // SetRect based on whether the overflow areas match aNewSize. |
9155 | 0 | // In the case where the overflow areas exactly match mRect but |
9156 | 0 | // do not match aNewSize, we need to store overflow in a property |
9157 | 0 | // so that our eventual SetRect/SetSize will know that it has to |
9158 | 0 | // reset our overflow areas. |
9159 | 0 | (l | t | r | b) != 0) { |
9160 | 0 | VisualDeltas oldDeltas = mOverflow.mVisualDeltas; |
9161 | 0 | // It's a "small" overflow area so we store the deltas for each edge |
9162 | 0 | // directly in the frame, rather than allocating a separate rect. |
9163 | 0 | // If they're all zero, that's fine; we're setting things to |
9164 | 0 | // no-overflow. |
9165 | 0 | mOverflow.mVisualDeltas.mLeft = l; |
9166 | 0 | mOverflow.mVisualDeltas.mTop = t; |
9167 | 0 | mOverflow.mVisualDeltas.mRight = r; |
9168 | 0 | mOverflow.mVisualDeltas.mBottom = b; |
9169 | 0 | // There was no scrollable overflow before, and there isn't now. |
9170 | 0 | return oldDeltas != mOverflow.mVisualDeltas; |
9171 | 0 | } else { |
9172 | 0 | bool changed = !aOverflowAreas.ScrollableOverflow().IsEqualEdges(nsRect(nsPoint(0, 0), GetSize())) || |
9173 | 0 | !aOverflowAreas.VisualOverflow().IsEqualEdges(GetVisualOverflowFromDeltas()); |
9174 | 0 |
|
9175 | 0 | // it's a large overflow area that we need to store as a property |
9176 | 0 | mOverflow.mType = NS_FRAME_OVERFLOW_LARGE; |
9177 | 0 | AddProperty(OverflowAreasProperty(), new nsOverflowAreas(aOverflowAreas)); |
9178 | 0 | return changed; |
9179 | 0 | } |
9180 | 0 | } |
9181 | | |
9182 | | /** |
9183 | | * Compute the union of the border boxes of aFrame and its descendants, |
9184 | | * in aFrame's coordinate space (if aApplyTransform is false) or its |
9185 | | * post-transform coordinate space (if aApplyTransform is true). |
9186 | | */ |
9187 | | static nsRect |
9188 | | UnionBorderBoxes(nsIFrame* aFrame, bool aApplyTransform, |
9189 | | bool& aOutValid, |
9190 | | const nsSize* aSizeOverride = nullptr, |
9191 | | const nsOverflowAreas* aOverflowOverride = nullptr) |
9192 | 0 | { |
9193 | 0 | const nsRect bounds(nsPoint(0, 0), |
9194 | 0 | aSizeOverride ? *aSizeOverride : aFrame->GetSize()); |
9195 | 0 |
|
9196 | 0 | // The SVG container frames besides SVGTextFrame do not maintain |
9197 | 0 | // an accurate mRect. It will make the outline be larger than |
9198 | 0 | // we expect, we need to make them narrow to their children's outline. |
9199 | 0 | // aOutValid is set to false if the returned nsRect is not valid |
9200 | 0 | // and should not be included in the outline rectangle. |
9201 | 0 | aOutValid = !(aFrame->GetStateBits() & NS_FRAME_SVG_LAYOUT) || |
9202 | 0 | !aFrame->IsFrameOfType(nsIFrame::eSVGContainer) || |
9203 | 0 | aFrame->IsSVGTextFrame(); |
9204 | 0 |
|
9205 | 0 | nsRect u; |
9206 | 0 |
|
9207 | 0 | if (!aFrame->FrameMaintainsOverflow()) { |
9208 | 0 | return u; |
9209 | 0 | } |
9210 | 0 | |
9211 | 0 | // Start from our border-box, transformed. See comment below about |
9212 | 0 | // transform of children. |
9213 | 0 | bool doTransform = aApplyTransform && aFrame->IsTransformed(); |
9214 | 0 | if (doTransform) { |
9215 | 0 | u = nsDisplayTransform::TransformRect(bounds, aFrame, &bounds); |
9216 | 0 | } else { |
9217 | 0 | u = bounds; |
9218 | 0 | } |
9219 | 0 |
|
9220 | 0 | // Only iterate through the children if the overflow areas suggest |
9221 | 0 | // that we might need to, and if the frame doesn't clip its overflow |
9222 | 0 | // anyway. |
9223 | 0 | if (aOverflowOverride) { |
9224 | 0 | if (!doTransform && |
9225 | 0 | bounds.IsEqualEdges(aOverflowOverride->VisualOverflow()) && |
9226 | 0 | bounds.IsEqualEdges(aOverflowOverride->ScrollableOverflow())) { |
9227 | 0 | return u; |
9228 | 0 | } |
9229 | 0 | } else { |
9230 | 0 | if (!doTransform && |
9231 | 0 | bounds.IsEqualEdges(aFrame->GetVisualOverflowRect()) && |
9232 | 0 | bounds.IsEqualEdges(aFrame->GetScrollableOverflowRect())) { |
9233 | 0 | return u; |
9234 | 0 | } |
9235 | 0 | } |
9236 | 0 | const nsStyleDisplay* disp = aFrame->StyleDisplay(); |
9237 | 0 | LayoutFrameType fType = aFrame->Type(); |
9238 | 0 | if (nsFrame::ShouldApplyOverflowClipping(aFrame, disp) || |
9239 | 0 | fType == LayoutFrameType::Scroll || |
9240 | 0 | fType == LayoutFrameType::ListControl || |
9241 | 0 | fType == LayoutFrameType::SVGOuterSVG) { |
9242 | 0 | return u; |
9243 | 0 | } |
9244 | 0 | |
9245 | 0 | const nsStyleEffects* effects = aFrame->StyleEffects(); |
9246 | 0 | Maybe<nsRect> clipPropClipRect = |
9247 | 0 | aFrame->GetClipPropClipRect(disp, effects, bounds.Size()); |
9248 | 0 |
|
9249 | 0 | // Iterate over all children except pop-ups. |
9250 | 0 | const nsIFrame::ChildListIDs skip(nsIFrame::kPopupList | |
9251 | 0 | nsIFrame::kSelectPopupList); |
9252 | 0 | for (nsIFrame::ChildListIterator childLists(aFrame); |
9253 | 0 | !childLists.IsDone(); childLists.Next()) { |
9254 | 0 | if (skip.Contains(childLists.CurrentID())) { |
9255 | 0 | continue; |
9256 | 0 | } |
9257 | 0 | |
9258 | 0 | nsFrameList children = childLists.CurrentList(); |
9259 | 0 | for (nsFrameList::Enumerator e(children); !e.AtEnd(); e.Next()) { |
9260 | 0 | nsIFrame* child = e.get(); |
9261 | 0 | // Note that passing |true| for aApplyTransform when |
9262 | 0 | // child->Combines3DTransformWithAncestors() is incorrect if our |
9263 | 0 | // aApplyTransform is false... but the opposite would be as |
9264 | 0 | // well. This is because elements within a preserve-3d scene |
9265 | 0 | // are always transformed up to the top of the scene. This |
9266 | 0 | // means we don't have a mechanism for getting a transform up to |
9267 | 0 | // an intermediate point within the scene. We choose to |
9268 | 0 | // over-transform rather than under-transform because this is |
9269 | 0 | // consistent with other overflow areas. |
9270 | 0 | bool validRect = true; |
9271 | 0 | nsRect childRect = UnionBorderBoxes(child, true, validRect) + |
9272 | 0 | child->GetPosition(); |
9273 | 0 |
|
9274 | 0 | if (!validRect) { |
9275 | 0 | continue; |
9276 | 0 | } |
9277 | 0 | |
9278 | 0 | if (clipPropClipRect) { |
9279 | 0 | // Intersect with the clip before transforming. |
9280 | 0 | childRect.IntersectRect(childRect, *clipPropClipRect); |
9281 | 0 | } |
9282 | 0 |
|
9283 | 0 | // Note that we transform each child separately according to |
9284 | 0 | // aFrame's transform, and then union, which gives a different |
9285 | 0 | // (smaller) result from unioning and then transforming the |
9286 | 0 | // union. This doesn't match the way we handle overflow areas |
9287 | 0 | // with 2-D transforms, though it does match the way we handle |
9288 | 0 | // overflow areas in preserve-3d 3-D scenes. |
9289 | 0 | if (doTransform && !child->Combines3DTransformWithAncestors()) { |
9290 | 0 | childRect = nsDisplayTransform::TransformRect(childRect, aFrame, &bounds); |
9291 | 0 | } |
9292 | 0 |
|
9293 | 0 | // If a SVGContainer has a non-SVGContainer child, we assign |
9294 | 0 | // its child's outline to this SVGContainer directly. |
9295 | 0 | if (!aOutValid && validRect) { |
9296 | 0 | u = childRect; |
9297 | 0 | aOutValid = true; |
9298 | 0 | } else { |
9299 | 0 | u.UnionRectEdges(u, childRect); |
9300 | 0 | } |
9301 | 0 | } |
9302 | 0 | } |
9303 | 0 |
|
9304 | 0 | return u; |
9305 | 0 | } |
9306 | | |
9307 | | static void |
9308 | | ComputeAndIncludeOutlineArea(nsIFrame* aFrame, nsOverflowAreas& aOverflowAreas, |
9309 | | const nsSize& aNewSize) |
9310 | 0 | { |
9311 | 0 | const nsStyleOutline* outline = aFrame->StyleOutline(); |
9312 | 0 | if (!outline->ShouldPaintOutline()) { |
9313 | 0 | return; |
9314 | 0 | } |
9315 | 0 | |
9316 | 0 | // When the outline property is set on a :-moz-block-inside-inline-wrapper |
9317 | 0 | // pseudo-element, it inherited that outline from the inline that was broken |
9318 | 0 | // because it contained a block. In that case, we don't want a really wide |
9319 | 0 | // outline if the block inside the inline is narrow, so union the actual |
9320 | 0 | // contents of the anonymous blocks. |
9321 | 0 | nsIFrame *frameForArea = aFrame; |
9322 | 0 | do { |
9323 | 0 | nsAtom *pseudoType = frameForArea->Style()->GetPseudo(); |
9324 | 0 | if (pseudoType != nsCSSAnonBoxes::mozBlockInsideInlineWrapper()) |
9325 | 0 | break; |
9326 | 0 | // If we're done, we really want it and all its later siblings. |
9327 | 0 | frameForArea = frameForArea->PrincipalChildList().FirstChild(); |
9328 | 0 | NS_ASSERTION(frameForArea, "anonymous block with no children?"); |
9329 | 0 | } while (frameForArea); |
9330 | 0 |
|
9331 | 0 | // Find the union of the border boxes of all descendants, or in |
9332 | 0 | // the block-in-inline case, all descendants we care about. |
9333 | 0 | // |
9334 | 0 | // Note that the interesting perspective-related cases are taken |
9335 | 0 | // care of by the code that handles those issues for overflow |
9336 | 0 | // calling FinishAndStoreOverflow again, which in turn calls this |
9337 | 0 | // function again. We still need to deal with preserve-3d a bit. |
9338 | 0 | nsRect innerRect; |
9339 | 0 | bool validRect; |
9340 | 0 | if (frameForArea == aFrame) { |
9341 | 0 | innerRect = UnionBorderBoxes(aFrame, false, validRect, &aNewSize, &aOverflowAreas); |
9342 | 0 | } else { |
9343 | 0 | for (; frameForArea; frameForArea = frameForArea->GetNextSibling()) { |
9344 | 0 | nsRect r(UnionBorderBoxes(frameForArea, true, validRect)); |
9345 | 0 |
|
9346 | 0 | // Adjust for offsets transforms up to aFrame's pre-transform |
9347 | 0 | // (i.e., normal) coordinate space; see comments in |
9348 | 0 | // UnionBorderBoxes for some of the subtlety here. |
9349 | 0 | for (nsIFrame *f = frameForArea, *parent = f->GetParent(); |
9350 | 0 | /* see middle of loop */; |
9351 | 0 | f = parent, parent = f->GetParent()) { |
9352 | 0 | r += f->GetPosition(); |
9353 | 0 | if (parent == aFrame) { |
9354 | 0 | break; |
9355 | 0 | } |
9356 | 0 | if (parent->IsTransformed() && !f->Combines3DTransformWithAncestors()) { |
9357 | 0 | r = nsDisplayTransform::TransformRect(r, parent); |
9358 | 0 | } |
9359 | 0 | } |
9360 | 0 |
|
9361 | 0 | innerRect.UnionRect(innerRect, r); |
9362 | 0 | } |
9363 | 0 | } |
9364 | 0 |
|
9365 | 0 | // Keep this code in sync with GetOutlineInnerRect in nsCSSRendering.cpp. |
9366 | 0 | aFrame->SetProperty(nsIFrame::OutlineInnerRectProperty(), |
9367 | 0 | new nsRect(innerRect)); |
9368 | 0 | const nscoord offset = outline->mOutlineOffset; |
9369 | 0 | nsRect outerRect(innerRect); |
9370 | 0 | bool useOutlineAuto = false; |
9371 | 0 | if (nsLayoutUtils::IsOutlineStyleAutoEnabled()) { |
9372 | 0 | useOutlineAuto = outline->mOutlineStyle == NS_STYLE_BORDER_STYLE_AUTO; |
9373 | 0 | if (MOZ_UNLIKELY(useOutlineAuto)) { |
9374 | 0 | nsPresContext* presContext = aFrame->PresContext(); |
9375 | 0 | nsITheme* theme = presContext->GetTheme(); |
9376 | 0 | if (theme && theme->ThemeSupportsWidget(presContext, aFrame, |
9377 | 0 | StyleAppearance::FocusOutline)) { |
9378 | 0 | outerRect.Inflate(offset); |
9379 | 0 | theme->GetWidgetOverflow(presContext->DeviceContext(), aFrame, |
9380 | 0 | StyleAppearance::FocusOutline, &outerRect); |
9381 | 0 | } else { |
9382 | 0 | useOutlineAuto = false; |
9383 | 0 | } |
9384 | 0 | } |
9385 | 0 | } |
9386 | 0 | if (MOZ_LIKELY(!useOutlineAuto)) { |
9387 | 0 | nscoord width = outline->GetOutlineWidth(); |
9388 | 0 | outerRect.Inflate(width + offset); |
9389 | 0 | } |
9390 | 0 |
|
9391 | 0 | nsRect& vo = aOverflowAreas.VisualOverflow(); |
9392 | 0 | vo.UnionRectEdges(vo, innerRect.Union(outerRect)); |
9393 | 0 | } |
9394 | | |
9395 | | bool |
9396 | | nsIFrame::FinishAndStoreOverflow(nsOverflowAreas& aOverflowAreas, |
9397 | | nsSize aNewSize, nsSize* aOldSize, |
9398 | | const nsStyleDisplay* aStyleDisplay) |
9399 | 0 | { |
9400 | 0 | MOZ_ASSERT(FrameMaintainsOverflow(), |
9401 | 0 | "Don't call - overflow rects not maintained on these SVG frames"); |
9402 | 0 |
|
9403 | 0 | const nsStyleDisplay* disp = StyleDisplayWithOptionalParam(aStyleDisplay); |
9404 | 0 | EffectSet* effectSet = EffectSet::GetEffectSet(this); |
9405 | 0 | bool hasTransform = IsTransformed(disp); |
9406 | 0 |
|
9407 | 0 | nsRect bounds(nsPoint(0, 0), aNewSize); |
9408 | 0 | // Store the passed in overflow area if we are a preserve-3d frame or we have |
9409 | 0 | // a transform, and it's not just the frame bounds. |
9410 | 0 | if (hasTransform || Combines3DTransformWithAncestors(disp)) { |
9411 | 0 | if (!aOverflowAreas.VisualOverflow().IsEqualEdges(bounds) || |
9412 | 0 | !aOverflowAreas.ScrollableOverflow().IsEqualEdges(bounds)) { |
9413 | 0 | nsOverflowAreas* initial = |
9414 | 0 | GetProperty(nsIFrame::InitialOverflowProperty()); |
9415 | 0 | if (!initial) { |
9416 | 0 | AddProperty(nsIFrame::InitialOverflowProperty(), |
9417 | 0 | new nsOverflowAreas(aOverflowAreas)); |
9418 | 0 | } else if (initial != &aOverflowAreas) { |
9419 | 0 | *initial = aOverflowAreas; |
9420 | 0 | } |
9421 | 0 | } else { |
9422 | 0 | DeleteProperty(nsIFrame::InitialOverflowProperty()); |
9423 | 0 | } |
9424 | | #ifdef DEBUG |
9425 | | SetProperty(nsIFrame::DebugInitialOverflowPropertyApplied(), true); |
9426 | | #endif |
9427 | 0 | } else { |
9428 | | #ifdef DEBUG |
9429 | | DeleteProperty(nsIFrame::DebugInitialOverflowPropertyApplied()); |
9430 | | #endif |
9431 | | } |
9432 | 0 |
|
9433 | 0 | nsSize oldSize = mRect.Size(); |
9434 | 0 | bool sizeChanged = ((aOldSize ? *aOldSize : oldSize) != aNewSize); |
9435 | 0 |
|
9436 | 0 | // Our frame size may not have been computed and set yet, but code under |
9437 | 0 | // functions such as ComputeEffectsRect (which we're about to call) use the |
9438 | 0 | // values that are stored in our frame rect to compute their results. We |
9439 | 0 | // need the results from those functions to be based on the frame size that |
9440 | 0 | // we *will* have, so we temporarily set our frame size here before calling |
9441 | 0 | // those functions. |
9442 | 0 | // |
9443 | 0 | // XXX Someone should document here why we revert the frame size before we |
9444 | 0 | // return rather than just leaving it set. |
9445 | 0 | // |
9446 | 0 | // We pass false here to avoid invalidating display items for this temporary |
9447 | 0 | // change. We sometimes reflow frames multiple times, with the final size being |
9448 | 0 | // the same as the initial. The single call to SetSize after reflow is done |
9449 | 0 | // will take care of invalidating display items if the size has actually |
9450 | 0 | // changed. |
9451 | 0 | SetSize(aNewSize, false); |
9452 | 0 |
|
9453 | 0 | const bool applyOverflowClipping = |
9454 | 0 | nsFrame::ShouldApplyOverflowClipping(this, disp); |
9455 | 0 |
|
9456 | 0 | if (ChildrenHavePerspective(disp) && sizeChanged) { |
9457 | 0 | RecomputePerspectiveChildrenOverflow(this); |
9458 | 0 |
|
9459 | 0 | if (!applyOverflowClipping) { |
9460 | 0 | aOverflowAreas.SetAllTo(bounds); |
9461 | 0 | DebugOnly<bool> ok = ComputeCustomOverflow(aOverflowAreas); |
9462 | 0 |
|
9463 | 0 | // ComputeCustomOverflow() should not return false, when |
9464 | 0 | // FrameMaintainsOverflow() returns true. |
9465 | 0 | MOZ_ASSERT(ok, "FrameMaintainsOverflow() != ComputeCustomOverflow()"); |
9466 | 0 |
|
9467 | 0 | UnionChildOverflow(aOverflowAreas); |
9468 | 0 | } |
9469 | 0 | } |
9470 | 0 |
|
9471 | 0 | // This is now called FinishAndStoreOverflow() instead of |
9472 | 0 | // StoreOverflow() because frame-generic ways of adding overflow |
9473 | 0 | // can happen here, e.g. CSS2 outline and native theme. |
9474 | 0 | // If the overflow area width or height is nscoord_MAX, then a |
9475 | 0 | // saturating union may have encounted an overflow, so the overflow may not |
9476 | 0 | // contain the frame border-box. Don't warn in that case. |
9477 | 0 | // Don't warn for SVG either, since SVG doesn't need the overflow area |
9478 | 0 | // to contain the frame bounds. |
9479 | 0 | NS_FOR_FRAME_OVERFLOW_TYPES(otype) { |
9480 | 0 | DebugOnly<nsRect*> r = &aOverflowAreas.Overflow(otype); |
9481 | 0 | NS_ASSERTION(aNewSize.width == 0 || aNewSize.height == 0 || |
9482 | 0 | r->width == nscoord_MAX || r->height == nscoord_MAX || |
9483 | 0 | (mState & NS_FRAME_SVG_LAYOUT) || |
9484 | 0 | r->Contains(nsRect(nsPoint(0,0), aNewSize)), |
9485 | 0 | "Computed overflow area must contain frame bounds"); |
9486 | 0 | } |
9487 | 0 |
|
9488 | 0 | // If we clip our children, clear accumulated overflow area. The |
9489 | 0 | // children are actually clipped to the padding-box, but since the |
9490 | 0 | // overflow area should include the entire border-box, just set it to |
9491 | 0 | // the border-box here. |
9492 | 0 | NS_ASSERTION((disp->mOverflowY == NS_STYLE_OVERFLOW_CLIP) == |
9493 | 0 | (disp->mOverflowX == NS_STYLE_OVERFLOW_CLIP), |
9494 | 0 | "If one overflow is clip, the other should be too"); |
9495 | 0 | if (applyOverflowClipping) { |
9496 | 0 | // The contents are actually clipped to the padding area |
9497 | 0 | aOverflowAreas.SetAllTo(bounds); |
9498 | 0 | } |
9499 | 0 |
|
9500 | 0 | // Overflow area must always include the frame's top-left and bottom-right, |
9501 | 0 | // even if the frame rect is empty (so we can scroll to those positions). |
9502 | 0 | // Pending a real fix for bug 426879, don't do this for inline frames |
9503 | 0 | // with zero width. |
9504 | 0 | // Do not do this for SVG either, since it will usually massively increase |
9505 | 0 | // the area unnecessarily. |
9506 | 0 | if ((aNewSize.width != 0 || !IsInlineFrame()) && |
9507 | 0 | !(GetStateBits() & NS_FRAME_SVG_LAYOUT)) { |
9508 | 0 | NS_FOR_FRAME_OVERFLOW_TYPES(otype) { |
9509 | 0 | nsRect& o = aOverflowAreas.Overflow(otype); |
9510 | 0 | o.UnionRectEdges(o, bounds); |
9511 | 0 | } |
9512 | 0 | } |
9513 | 0 |
|
9514 | 0 | // Note that NS_STYLE_OVERFLOW_CLIP doesn't clip the frame background, |
9515 | 0 | // so we add theme background overflow here so it's not clipped. |
9516 | 0 | if (!::IsXULBoxWrapped(this) && IsThemed(disp)) { |
9517 | 0 | nsRect r(bounds); |
9518 | 0 | nsPresContext *presContext = PresContext(); |
9519 | 0 | if (presContext->GetTheme()-> |
9520 | 0 | GetWidgetOverflow(presContext->DeviceContext(), this, |
9521 | 0 | disp->mAppearance, &r)) { |
9522 | 0 | nsRect& vo = aOverflowAreas.VisualOverflow(); |
9523 | 0 | vo.UnionRectEdges(vo, r); |
9524 | 0 | } |
9525 | 0 | } |
9526 | 0 |
|
9527 | 0 | ComputeAndIncludeOutlineArea(this, aOverflowAreas, aNewSize); |
9528 | 0 |
|
9529 | 0 | // Nothing in here should affect scrollable overflow. |
9530 | 0 | aOverflowAreas.VisualOverflow() = |
9531 | 0 | ComputeEffectsRect(this, aOverflowAreas.VisualOverflow(), aNewSize); |
9532 | 0 |
|
9533 | 0 | // Absolute position clipping |
9534 | 0 | const nsStyleEffects* effects = StyleEffects(); |
9535 | 0 | Maybe<nsRect> clipPropClipRect = |
9536 | 0 | GetClipPropClipRect(disp, effects, aNewSize); |
9537 | 0 | if (clipPropClipRect) { |
9538 | 0 | NS_FOR_FRAME_OVERFLOW_TYPES(otype) { |
9539 | 0 | nsRect& o = aOverflowAreas.Overflow(otype); |
9540 | 0 | o.IntersectRect(o, *clipPropClipRect); |
9541 | 0 | } |
9542 | 0 | } |
9543 | 0 |
|
9544 | 0 | /* If we're transformed, transform the overflow rect by the current transformation. */ |
9545 | 0 | if (hasTransform) { |
9546 | 0 | SetProperty(nsIFrame::PreTransformOverflowAreasProperty(), |
9547 | 0 | new nsOverflowAreas(aOverflowAreas)); |
9548 | 0 |
|
9549 | 0 | if (Combines3DTransformWithAncestors(disp)) { |
9550 | 0 | /* If we're a preserve-3d leaf frame, then our pre-transform overflow should be correct. Our |
9551 | 0 | * post-transform overflow is empty though, because we only contribute to the overflow area |
9552 | 0 | * of the preserve-3d root frame. |
9553 | 0 | * If we're an intermediate frame then the pre-transform overflow should contain all our |
9554 | 0 | * non-preserve-3d children, which is what we want. Again we have no post-transform overflow. |
9555 | 0 | */ |
9556 | 0 | aOverflowAreas.SetAllTo(nsRect()); |
9557 | 0 | } else { |
9558 | 0 | NS_FOR_FRAME_OVERFLOW_TYPES(otype) { |
9559 | 0 | nsRect& o = aOverflowAreas.Overflow(otype); |
9560 | 0 | o = nsDisplayTransform::TransformRect(o, this); |
9561 | 0 | } |
9562 | 0 |
|
9563 | 0 | /* If we're the root of the 3d context, then we want to include the overflow areas of all |
9564 | 0 | * the participants. This won't have happened yet as the code above set their overflow |
9565 | 0 | * area to empty. Manually collect these overflow areas now. |
9566 | 0 | */ |
9567 | 0 | if (Extend3DContext(disp, effectSet)) { |
9568 | 0 | ComputePreserve3DChildrenOverflow(aOverflowAreas); |
9569 | 0 | } |
9570 | 0 | } |
9571 | 0 | } else { |
9572 | 0 | DeleteProperty(nsIFrame::PreTransformOverflowAreasProperty()); |
9573 | 0 | } |
9574 | 0 |
|
9575 | 0 | /* Revert the size change in case some caller is depending on this. */ |
9576 | 0 | SetSize(oldSize, false); |
9577 | 0 |
|
9578 | 0 | bool anyOverflowChanged; |
9579 | 0 | if (aOverflowAreas != nsOverflowAreas(bounds, bounds)) { |
9580 | 0 | anyOverflowChanged = SetOverflowAreas(aOverflowAreas); |
9581 | 0 | } else { |
9582 | 0 | anyOverflowChanged = ClearOverflowRects(); |
9583 | 0 | } |
9584 | 0 |
|
9585 | 0 | if (anyOverflowChanged) { |
9586 | 0 | SVGObserverUtils::InvalidateDirectRenderingObservers(this); |
9587 | 0 | } |
9588 | 0 | return anyOverflowChanged; |
9589 | 0 | } |
9590 | | |
9591 | | void |
9592 | | nsIFrame::RecomputePerspectiveChildrenOverflow(const nsIFrame* aStartFrame) |
9593 | 0 | { |
9594 | 0 | nsIFrame::ChildListIterator lists(this); |
9595 | 0 | for (; !lists.IsDone(); lists.Next()) { |
9596 | 0 | nsFrameList::Enumerator childFrames(lists.CurrentList()); |
9597 | 0 | for (; !childFrames.AtEnd(); childFrames.Next()) { |
9598 | 0 | nsIFrame* child = childFrames.get(); |
9599 | 0 | if (!child->FrameMaintainsOverflow()) { |
9600 | 0 | continue; // frame does not maintain overflow rects |
9601 | 0 | } |
9602 | 0 | if (child->HasPerspective()) { |
9603 | 0 | nsOverflowAreas* overflow = |
9604 | 0 | child->GetProperty(nsIFrame::InitialOverflowProperty()); |
9605 | 0 | nsRect bounds(nsPoint(0, 0), child->GetSize()); |
9606 | 0 | if (overflow) { |
9607 | 0 | nsOverflowAreas overflowCopy = *overflow; |
9608 | 0 | child->FinishAndStoreOverflow(overflowCopy, bounds.Size()); |
9609 | 0 | } else { |
9610 | 0 | nsOverflowAreas boundsOverflow; |
9611 | 0 | boundsOverflow.SetAllTo(bounds); |
9612 | 0 | child->FinishAndStoreOverflow(boundsOverflow, bounds.Size()); |
9613 | 0 | } |
9614 | 0 | } else if (child->GetContainingBlock(SKIP_SCROLLED_FRAME) == aStartFrame) { |
9615 | 0 | // If a frame is using perspective, then the size used to compute |
9616 | 0 | // perspective-origin is the size of the frame belonging to its parent |
9617 | 0 | // style. We must find any descendant frames using our size |
9618 | 0 | // (by recursing into frames that have the same containing block) |
9619 | 0 | // to update their overflow rects too. |
9620 | 0 | child->RecomputePerspectiveChildrenOverflow(aStartFrame); |
9621 | 0 | } |
9622 | 0 | } |
9623 | 0 | } |
9624 | 0 | } |
9625 | | |
9626 | | void |
9627 | | nsIFrame::ComputePreserve3DChildrenOverflow(nsOverflowAreas& aOverflowAreas) |
9628 | 0 | { |
9629 | 0 | // Find all descendants that participate in the 3d context, and include their overflow. |
9630 | 0 | // These descendants have an empty overflow, so won't have been included in the normal |
9631 | 0 | // overflow calculation. Any children that don't participate have normal overflow, |
9632 | 0 | // so will have been included already. |
9633 | 0 |
|
9634 | 0 | nsRect childVisual; |
9635 | 0 | nsRect childScrollable; |
9636 | 0 | nsIFrame::ChildListIterator lists(this); |
9637 | 0 | for (; !lists.IsDone(); lists.Next()) { |
9638 | 0 | nsFrameList::Enumerator childFrames(lists.CurrentList()); |
9639 | 0 | for (; !childFrames.AtEnd(); childFrames.Next()) { |
9640 | 0 | nsIFrame* child = childFrames.get(); |
9641 | 0 |
|
9642 | 0 | // If this child participates in the 3d context, then take the pre-transform |
9643 | 0 | // region (which contains all descendants that aren't participating in the 3d context) |
9644 | 0 | // and transform it into the 3d context root coordinate space. |
9645 | 0 | const nsStyleDisplay* childDisp = child->StyleDisplay(); |
9646 | 0 | if (child->Combines3DTransformWithAncestors(childDisp)) { |
9647 | 0 | nsOverflowAreas childOverflow = child->GetOverflowAreasRelativeToSelf(); |
9648 | 0 |
|
9649 | 0 | NS_FOR_FRAME_OVERFLOW_TYPES(otype) { |
9650 | 0 | nsRect& o = childOverflow.Overflow(otype); |
9651 | 0 | o = nsDisplayTransform::TransformRect(o, child); |
9652 | 0 | } |
9653 | 0 |
|
9654 | 0 | aOverflowAreas.UnionWith(childOverflow); |
9655 | 0 |
|
9656 | 0 | // If this child also extends the 3d context, then recurse into it |
9657 | 0 | // looking for more participants. |
9658 | 0 | if (child->Extend3DContext(childDisp)) { |
9659 | 0 | child->ComputePreserve3DChildrenOverflow(aOverflowAreas); |
9660 | 0 | } |
9661 | 0 | } |
9662 | 0 | } |
9663 | 0 | } |
9664 | 0 | } |
9665 | | |
9666 | | uint32_t |
9667 | | nsIFrame::GetDepthInFrameTree() const |
9668 | 0 | { |
9669 | 0 | uint32_t result = 0; |
9670 | 0 | for (nsContainerFrame* ancestor = GetParent(); ancestor; |
9671 | 0 | ancestor = ancestor->GetParent()) { |
9672 | 0 | result++; |
9673 | 0 | } |
9674 | 0 | return result; |
9675 | 0 | } |
9676 | | |
9677 | | void |
9678 | | nsFrame::ConsiderChildOverflow(nsOverflowAreas& aOverflowAreas, |
9679 | | nsIFrame* aChildFrame) |
9680 | 0 | { |
9681 | 0 | if (StyleDisplay()->IsContainLayout() && |
9682 | 0 | IsFrameOfType(eSupportsContainLayoutAndPaint)) { |
9683 | 0 | // If we have layout containment and are not a non-atomic, inline-level |
9684 | 0 | // principal box, we should only consider our child's visual (ink) overflow, |
9685 | 0 | // leaving the scrollable regions of the parent unaffected. |
9686 | 0 | // Note: scrollable overflow is a subset of visual overflow, |
9687 | 0 | // so this has the same affect as unioning the child's visual and |
9688 | 0 | // scrollable overflow with the parent's visual overflow. |
9689 | 0 | // XXX doesn't work correctly for floats - bug 1481951 |
9690 | 0 | nsRect childVisual = aChildFrame->GetVisualOverflowRect(); |
9691 | 0 | nsOverflowAreas combined = nsOverflowAreas( |
9692 | 0 | childVisual, |
9693 | 0 | nsRect()); |
9694 | 0 | aOverflowAreas.UnionWith(combined + aChildFrame->GetPosition()); |
9695 | 0 | } else { |
9696 | 0 | aOverflowAreas.UnionWith(aChildFrame->GetOverflowAreas() + |
9697 | 0 | aChildFrame->GetPosition()); |
9698 | 0 | } |
9699 | 0 | } |
9700 | | |
9701 | | bool |
9702 | | nsFrame::ShouldAvoidBreakInside(const ReflowInput& aReflowInput) const |
9703 | 0 | { |
9704 | 0 | const auto* disp = StyleDisplay(); |
9705 | 0 | return !aReflowInput.mFlags.mIsTopOfPage && |
9706 | 0 | NS_STYLE_PAGE_BREAK_AVOID == disp->mBreakInside && |
9707 | 0 | !(HasAnyStateBits(NS_FRAME_OUT_OF_FLOW) && IsAbsolutelyPositioned(disp)) && |
9708 | 0 | !GetPrevInFlow(); |
9709 | 0 | } |
9710 | | |
9711 | | /** |
9712 | | * This function takes a frame that is part of a block-in-inline split, |
9713 | | * and _if_ that frame is an anonymous block created by an ib split it |
9714 | | * returns the block's preceding inline. This is needed because the |
9715 | | * split inline's style is the parent of the anonymous block's style. |
9716 | | * |
9717 | | * If aFrame is not an anonymous block, null is returned. |
9718 | | */ |
9719 | | static nsIFrame* |
9720 | | GetIBSplitSiblingForAnonymousBlock(const nsIFrame* aFrame) |
9721 | 0 | { |
9722 | 0 | MOZ_ASSERT(aFrame, "Must have a non-null frame!"); |
9723 | 0 | NS_ASSERTION(aFrame->GetStateBits() & NS_FRAME_PART_OF_IBSPLIT, |
9724 | 0 | "GetIBSplitSibling should only be called on ib-split frames"); |
9725 | 0 |
|
9726 | 0 | nsAtom* type = aFrame->Style()->GetPseudo(); |
9727 | 0 | if (type != nsCSSAnonBoxes::mozBlockInsideInlineWrapper()) { |
9728 | 0 | // it's not an anonymous block |
9729 | 0 | return nullptr; |
9730 | 0 | } |
9731 | 0 | |
9732 | 0 | // Find the first continuation of the frame. (Ugh. This ends up |
9733 | 0 | // being O(N^2) when it is called O(N) times.) |
9734 | 0 | aFrame = aFrame->FirstContinuation(); |
9735 | 0 |
|
9736 | 0 | /* |
9737 | 0 | * Now look up the nsGkAtoms::IBSplitPrevSibling |
9738 | 0 | * property. |
9739 | 0 | */ |
9740 | 0 | nsIFrame *ibSplitSibling = |
9741 | 0 | aFrame->GetProperty(nsIFrame::IBSplitPrevSibling()); |
9742 | 0 | NS_ASSERTION(ibSplitSibling, "Broken frame tree?"); |
9743 | 0 | return ibSplitSibling; |
9744 | 0 | } |
9745 | | |
9746 | | /** |
9747 | | * Get the parent, corrected for the mangled frame tree resulting from |
9748 | | * having a block within an inline. The result only differs from the |
9749 | | * result of |GetParent| when |GetParent| returns an anonymous block |
9750 | | * that was created for an element that was 'display: inline' because |
9751 | | * that element contained a block. |
9752 | | * |
9753 | | * Also skip anonymous scrolled-content parents; inherit directly from the |
9754 | | * outer scroll frame. |
9755 | | * |
9756 | | * Also skip NAC parents if the child frame is NAC. |
9757 | | */ |
9758 | | static nsIFrame* |
9759 | | GetCorrectedParent(const nsIFrame* aFrame) |
9760 | 0 | { |
9761 | 0 | nsIFrame* parent = aFrame->GetParent(); |
9762 | 0 | if (!parent) { |
9763 | 0 | return nullptr; |
9764 | 0 | } |
9765 | 0 | |
9766 | 0 | // For a table caption we want the _inner_ table frame (unless it's anonymous) |
9767 | 0 | // as the style parent. |
9768 | 0 | if (aFrame->IsTableCaption()) { |
9769 | 0 | nsIFrame* innerTable = parent->PrincipalChildList().FirstChild(); |
9770 | 0 | if (!innerTable->Style()->GetPseudo()) { |
9771 | 0 | return innerTable; |
9772 | 0 | } |
9773 | 0 | } |
9774 | 0 | |
9775 | 0 | // Table wrappers are always anon boxes; if we're in here for an outer |
9776 | 0 | // table, that actually means its the _inner_ table that wants to |
9777 | 0 | // know its parent. So get the pseudo of the inner in that case. |
9778 | 0 | nsAtom* pseudo = aFrame->Style()->GetPseudo(); |
9779 | 0 | if (pseudo == nsCSSAnonBoxes::tableWrapper()) { |
9780 | 0 | pseudo = aFrame->PrincipalChildList().FirstChild()->Style()->GetPseudo(); |
9781 | 0 | } |
9782 | 0 |
|
9783 | 0 | // Prevent a NAC pseudo-element from inheriting from its NAC parent, and |
9784 | 0 | // inherit from the NAC generator element instead. |
9785 | 0 | if (pseudo) { |
9786 | 0 | MOZ_ASSERT(aFrame->GetContent()); |
9787 | 0 | Element* element = Element::FromNode(aFrame->GetContent()); |
9788 | 0 | // Make sure to avoid doing the fixup for non-element-backed pseudos like |
9789 | 0 | // ::first-line and such. |
9790 | 0 | if (element && |
9791 | 0 | !element->IsRootOfNativeAnonymousSubtree() && |
9792 | 0 | element->GetPseudoElementType() == aFrame->Style()->GetPseudoType()) { |
9793 | 0 | while (parent->GetContent() && |
9794 | 0 | !parent->GetContent()->IsRootOfAnonymousSubtree()) { |
9795 | 0 | parent = parent->GetInFlowParent(); |
9796 | 0 | } |
9797 | 0 | parent = parent->GetInFlowParent(); |
9798 | 0 | } |
9799 | 0 | } |
9800 | 0 |
|
9801 | 0 | return nsFrame::CorrectStyleParentFrame(parent, pseudo); |
9802 | 0 | } |
9803 | | |
9804 | | /* static */ |
9805 | | nsIFrame* |
9806 | | nsFrame::CorrectStyleParentFrame(nsIFrame* aProspectiveParent, |
9807 | | nsAtom* aChildPseudo) |
9808 | 0 | { |
9809 | 0 | MOZ_ASSERT(aProspectiveParent, "Must have a prospective parent"); |
9810 | 0 |
|
9811 | 0 | if (aChildPseudo) { |
9812 | 0 | // Non-inheriting anon boxes have no style parent frame at all. |
9813 | 0 | if (nsCSSAnonBoxes::IsNonInheritingAnonBox(aChildPseudo)) { |
9814 | 0 | return nullptr; |
9815 | 0 | } |
9816 | 0 | |
9817 | 0 | // Other anon boxes are parented to their actual parent already, except |
9818 | 0 | // for non-elements. Those should not be treated as an anon box. |
9819 | 0 | if (!nsCSSAnonBoxes::IsNonElement(aChildPseudo) && |
9820 | 0 | nsCSSAnonBoxes::IsAnonBox(aChildPseudo)) { |
9821 | 0 | NS_ASSERTION(aChildPseudo != nsCSSAnonBoxes::mozBlockInsideInlineWrapper(), |
9822 | 0 | "Should have dealt with kids that have " |
9823 | 0 | "NS_FRAME_PART_OF_IBSPLIT elsewhere"); |
9824 | 0 | return aProspectiveParent; |
9825 | 0 | } |
9826 | 0 | } |
9827 | 0 |
|
9828 | 0 | // Otherwise, walk up out of all anon boxes. For placeholder frames, walk out |
9829 | 0 | // of all pseudo-elements as well. Otherwise ReparentComputedStyle could cause |
9830 | 0 | // style data to be out of sync with the frame tree. |
9831 | 0 | nsIFrame* parent = aProspectiveParent; |
9832 | 0 | do { |
9833 | 0 | if (parent->GetStateBits() & NS_FRAME_PART_OF_IBSPLIT) { |
9834 | 0 | nsIFrame* sibling = GetIBSplitSiblingForAnonymousBlock(parent); |
9835 | 0 |
|
9836 | 0 | if (sibling) { |
9837 | 0 | // |parent| was a block in an {ib} split; use the inline as |
9838 | 0 | // |the style parent. |
9839 | 0 | parent = sibling; |
9840 | 0 | } |
9841 | 0 | } |
9842 | 0 |
|
9843 | 0 | nsAtom* parentPseudo = parent->Style()->GetPseudo(); |
9844 | 0 | if (!parentPseudo || |
9845 | 0 | (!nsCSSAnonBoxes::IsAnonBox(parentPseudo) && |
9846 | 0 | // nsPlaceholderFrame pases in nsGkAtoms::placeholderFrame for |
9847 | 0 | // aChildPseudo (even though that's not a valid pseudo-type) just to |
9848 | 0 | // trigger this behavior of walking up to the nearest non-pseudo |
9849 | 0 | // ancestor. |
9850 | 0 | aChildPseudo != nsGkAtoms::placeholderFrame)) { |
9851 | 0 | return parent; |
9852 | 0 | } |
9853 | 0 | |
9854 | 0 | parent = parent->GetInFlowParent(); |
9855 | 0 | } while (parent); |
9856 | 0 |
|
9857 | 0 | if (aProspectiveParent->Style()->GetPseudo() == |
9858 | 0 | nsCSSAnonBoxes::viewportScroll()) { |
9859 | 0 | // aProspectiveParent is the scrollframe for a viewport |
9860 | 0 | // and the kids are the anonymous scrollbars |
9861 | 0 | return aProspectiveParent; |
9862 | 0 | } |
9863 | 0 | |
9864 | 0 | // We can get here if the root element is absolutely positioned. |
9865 | 0 | // We can't test for this very accurately, but it can only happen |
9866 | 0 | // when the prospective parent is a canvas frame. |
9867 | 0 | NS_ASSERTION(aProspectiveParent->IsCanvasFrame(), |
9868 | 0 | "Should have found a parent before this"); |
9869 | 0 | return nullptr; |
9870 | 0 | } |
9871 | | |
9872 | | ComputedStyle* |
9873 | | nsFrame::DoGetParentComputedStyle(nsIFrame** aProviderFrame) const |
9874 | 0 | { |
9875 | 0 | *aProviderFrame = nullptr; |
9876 | 0 |
|
9877 | 0 | // Handle display:contents and the root frame, when there's no parent frame |
9878 | 0 | // to inherit from. |
9879 | 0 | if (MOZ_LIKELY(mContent)) { |
9880 | 0 | Element* parentElement = mContent->GetFlattenedTreeParentElement(); |
9881 | 0 | if (MOZ_LIKELY(parentElement)) { |
9882 | 0 | nsAtom* pseudo = Style()->GetPseudo(); |
9883 | 0 | if (!pseudo || !mContent->IsElement() || |
9884 | 0 | (!nsCSSAnonBoxes::IsAnonBox(pseudo) && |
9885 | 0 | // Ensure that we don't return the display:contents style |
9886 | 0 | // of the parent content for pseudos that have the same content |
9887 | 0 | // as their primary frame (like -moz-list-bullets do): |
9888 | 0 | IsPrimaryFrame()) || |
9889 | 0 | /* if next is true then it's really a request for the table frame's |
9890 | 0 | parent context, see nsTable[Outer]Frame::GetParentComputedStyle. */ |
9891 | 0 | pseudo == nsCSSAnonBoxes::tableWrapper()) { |
9892 | 0 | if (Servo_Element_IsDisplayContents(parentElement)) { |
9893 | 0 | RefPtr<ComputedStyle> style = |
9894 | 0 | PresShell()->StyleSet()->ResolveServoStyle(*parentElement); |
9895 | 0 | // NOTE(emilio): we return a weak reference because the element also |
9896 | 0 | // holds the style context alive. This is a bit silly (we could've |
9897 | 0 | // returned a weak ref directly), but it's probably not worth |
9898 | 0 | // optimizing, given this function has just one caller which is rare, |
9899 | 0 | // and this path is rare itself. |
9900 | 0 | return style; |
9901 | 0 | } |
9902 | 0 | } |
9903 | 0 | } else { |
9904 | 0 | if (!Style()->GetPseudo()) { |
9905 | 0 | // We're a frame for the root. We have no style parent. |
9906 | 0 | return nullptr; |
9907 | 0 | } |
9908 | 0 | } |
9909 | 0 | } |
9910 | 0 | |
9911 | 0 | if (!(mState & NS_FRAME_OUT_OF_FLOW)) { |
9912 | 0 | /* |
9913 | 0 | * If this frame is an anonymous block created when an inline with a block |
9914 | 0 | * inside it got split, then the parent style is on its preceding inline. We |
9915 | 0 | * can get to it using GetIBSplitSiblingForAnonymousBlock. |
9916 | 0 | */ |
9917 | 0 | if (mState & NS_FRAME_PART_OF_IBSPLIT) { |
9918 | 0 | nsIFrame* ibSplitSibling = GetIBSplitSiblingForAnonymousBlock(this); |
9919 | 0 | if (ibSplitSibling) { |
9920 | 0 | return (*aProviderFrame = ibSplitSibling)->Style(); |
9921 | 0 | } |
9922 | 0 | } |
9923 | 0 | |
9924 | 0 | // If this frame is one of the blocks that split an inline, we must |
9925 | 0 | // return the "special" inline parent, i.e., the parent that this |
9926 | 0 | // frame would have if we didn't mangle the frame structure. |
9927 | 0 | *aProviderFrame = GetCorrectedParent(this); |
9928 | 0 | return *aProviderFrame ? (*aProviderFrame)->Style() : nullptr; |
9929 | 0 | } |
9930 | 0 |
|
9931 | 0 | // We're an out-of-flow frame. For out-of-flow frames, we must |
9932 | 0 | // resolve underneath the placeholder's parent. The placeholder is |
9933 | 0 | // reached from the first-in-flow. |
9934 | 0 | nsPlaceholderFrame* placeholder = FirstInFlow()->GetPlaceholderFrame(); |
9935 | 0 | if (!placeholder) { |
9936 | 0 | MOZ_ASSERT_UNREACHABLE("no placeholder frame for out-of-flow frame"); |
9937 | 0 | *aProviderFrame = GetCorrectedParent(this); |
9938 | 0 | return *aProviderFrame ? (*aProviderFrame)->Style() : nullptr; |
9939 | 0 | } |
9940 | 0 | return placeholder->GetParentComputedStyleForOutOfFlow(aProviderFrame); |
9941 | 0 | } |
9942 | | |
9943 | | void |
9944 | | nsFrame::GetLastLeaf(nsPresContext* aPresContext, nsIFrame **aFrame) |
9945 | 0 | { |
9946 | 0 | if (!aFrame || !*aFrame) |
9947 | 0 | return; |
9948 | 0 | nsIFrame *child = *aFrame; |
9949 | 0 | //if we are a block frame then go for the last line of 'this' |
9950 | 0 | while (1){ |
9951 | 0 | child = child->PrincipalChildList().FirstChild(); |
9952 | 0 | if (!child) |
9953 | 0 | return;//nothing to do |
9954 | 0 | nsIFrame* siblingFrame; |
9955 | 0 | nsIContent* content; |
9956 | 0 | //ignore anonymous elements, e.g. mozTableAdd* mozTableRemove* |
9957 | 0 | //see bug 278197 comment #12 #13 for details |
9958 | 0 | while ((siblingFrame = child->GetNextSibling()) && |
9959 | 0 | (content = siblingFrame->GetContent()) && |
9960 | 0 | !content->IsRootOfNativeAnonymousSubtree()) |
9961 | 0 | child = siblingFrame; |
9962 | 0 | *aFrame = child; |
9963 | 0 | } |
9964 | 0 | } |
9965 | | |
9966 | | void |
9967 | | nsFrame::GetFirstLeaf(nsPresContext* aPresContext, nsIFrame **aFrame) |
9968 | 0 | { |
9969 | 0 | if (!aFrame || !*aFrame) |
9970 | 0 | return; |
9971 | 0 | nsIFrame *child = *aFrame; |
9972 | 0 | while (1){ |
9973 | 0 | child = child->PrincipalChildList().FirstChild(); |
9974 | 0 | if (!child) |
9975 | 0 | return;//nothing to do |
9976 | 0 | *aFrame = child; |
9977 | 0 | } |
9978 | 0 | } |
9979 | | |
9980 | | /* virtual */ bool |
9981 | | nsIFrame::IsFocusable(int32_t *aTabIndex, bool aWithMouse) |
9982 | 0 | { |
9983 | 0 | int32_t tabIndex = -1; |
9984 | 0 | if (aTabIndex) { |
9985 | 0 | *aTabIndex = -1; // Default for early return is not focusable |
9986 | 0 | } |
9987 | 0 | bool isFocusable = false; |
9988 | 0 |
|
9989 | 0 | if (mContent && mContent->IsElement() && IsVisibleConsideringAncestors() && |
9990 | 0 | Style()->GetPseudo() != nsCSSAnonBoxes::anonymousFlexItem() && |
9991 | 0 | Style()->GetPseudo() != nsCSSAnonBoxes::anonymousGridItem()) { |
9992 | 0 | const nsStyleUI* ui = StyleUI(); |
9993 | 0 | if (ui->mUserFocus != StyleUserFocus::Ignore && |
9994 | 0 | ui->mUserFocus != StyleUserFocus::None) { |
9995 | 0 | // Pass in default tabindex of -1 for nonfocusable and 0 for focusable |
9996 | 0 | tabIndex = 0; |
9997 | 0 | } |
9998 | 0 | isFocusable = mContent->IsFocusable(&tabIndex, aWithMouse); |
9999 | 0 | if (!isFocusable && !aWithMouse && IsScrollFrame() && |
10000 | 0 | mContent->IsHTMLElement() && |
10001 | 0 | !mContent->IsRootOfNativeAnonymousSubtree() && mContent->GetParent() && |
10002 | 0 | !mContent->AsElement()->HasAttr(kNameSpaceID_None, nsGkAtoms::tabindex)) { |
10003 | 0 | // Elements with scrollable view are focusable with script & tabbable |
10004 | 0 | // Otherwise you couldn't scroll them with keyboard, which is |
10005 | 0 | // an accessibility issue (e.g. Section 508 rules) |
10006 | 0 | // However, we don't make them to be focusable with the mouse, |
10007 | 0 | // because the extra focus outlines are considered unnecessarily ugly. |
10008 | 0 | // When clicked on, the selection position within the element |
10009 | 0 | // will be enough to make them keyboard scrollable. |
10010 | 0 | nsIScrollableFrame *scrollFrame = do_QueryFrame(this); |
10011 | 0 | if (scrollFrame && |
10012 | 0 | !scrollFrame->GetScrollStyles().IsHiddenInBothDirections() && |
10013 | 0 | !scrollFrame->GetScrollRange().IsEqualEdges(nsRect(0, 0, 0, 0))) { |
10014 | 0 | // Scroll bars will be used for overflow |
10015 | 0 | isFocusable = true; |
10016 | 0 | tabIndex = 0; |
10017 | 0 | } |
10018 | 0 | } |
10019 | 0 | } |
10020 | 0 |
|
10021 | 0 | if (aTabIndex) { |
10022 | 0 | *aTabIndex = tabIndex; |
10023 | 0 | } |
10024 | 0 | return isFocusable; |
10025 | 0 | } |
10026 | | |
10027 | | /** |
10028 | | * @return true if this text frame ends with a newline character which is |
10029 | | * treated as preformatted. It should return false if this is not a text frame. |
10030 | | */ |
10031 | | bool |
10032 | | nsIFrame::HasSignificantTerminalNewline() const |
10033 | 0 | { |
10034 | 0 | return false; |
10035 | 0 | } |
10036 | | |
10037 | | static uint8_t |
10038 | | ConvertSVGDominantBaselineToVerticalAlign(uint8_t aDominantBaseline) |
10039 | 0 | { |
10040 | 0 | // Most of these are approximate mappings. |
10041 | 0 | switch (aDominantBaseline) { |
10042 | 0 | case NS_STYLE_DOMINANT_BASELINE_HANGING: |
10043 | 0 | case NS_STYLE_DOMINANT_BASELINE_TEXT_BEFORE_EDGE: |
10044 | 0 | return NS_STYLE_VERTICAL_ALIGN_TEXT_TOP; |
10045 | 0 | case NS_STYLE_DOMINANT_BASELINE_TEXT_AFTER_EDGE: |
10046 | 0 | case NS_STYLE_DOMINANT_BASELINE_IDEOGRAPHIC: |
10047 | 0 | return NS_STYLE_VERTICAL_ALIGN_TEXT_BOTTOM; |
10048 | 0 | case NS_STYLE_DOMINANT_BASELINE_CENTRAL: |
10049 | 0 | case NS_STYLE_DOMINANT_BASELINE_MIDDLE: |
10050 | 0 | case NS_STYLE_DOMINANT_BASELINE_MATHEMATICAL: |
10051 | 0 | return NS_STYLE_VERTICAL_ALIGN_MIDDLE; |
10052 | 0 | case NS_STYLE_DOMINANT_BASELINE_AUTO: |
10053 | 0 | case NS_STYLE_DOMINANT_BASELINE_ALPHABETIC: |
10054 | 0 | return NS_STYLE_VERTICAL_ALIGN_BASELINE; |
10055 | 0 | case NS_STYLE_DOMINANT_BASELINE_USE_SCRIPT: |
10056 | 0 | case NS_STYLE_DOMINANT_BASELINE_NO_CHANGE: |
10057 | 0 | case NS_STYLE_DOMINANT_BASELINE_RESET_SIZE: |
10058 | 0 | // These three should not simply map to 'baseline', but we don't |
10059 | 0 | // support the complex baseline model that SVG 1.1 has and which |
10060 | 0 | // css3-linebox now defines. |
10061 | 0 | return NS_STYLE_VERTICAL_ALIGN_BASELINE; |
10062 | 0 | default: |
10063 | 0 | MOZ_ASSERT_UNREACHABLE("unexpected aDominantBaseline value"); |
10064 | 0 | return NS_STYLE_VERTICAL_ALIGN_BASELINE; |
10065 | 0 | } |
10066 | 0 | } |
10067 | | |
10068 | | uint8_t |
10069 | | nsIFrame::VerticalAlignEnum() const |
10070 | 0 | { |
10071 | 0 | if (nsSVGUtils::IsInSVGTextSubtree(this)) { |
10072 | 0 | uint8_t dominantBaseline; |
10073 | 0 | for (const nsIFrame* frame = this; frame; frame = frame->GetParent()) { |
10074 | 0 | dominantBaseline = frame->StyleSVGReset()->mDominantBaseline; |
10075 | 0 | if (dominantBaseline != NS_STYLE_DOMINANT_BASELINE_AUTO || |
10076 | 0 | frame->IsSVGTextFrame()) { |
10077 | 0 | break; |
10078 | 0 | } |
10079 | 0 | } |
10080 | 0 | return ConvertSVGDominantBaselineToVerticalAlign(dominantBaseline); |
10081 | 0 | } |
10082 | 0 |
|
10083 | 0 | const nsStyleCoord& verticalAlign = StyleDisplay()->mVerticalAlign; |
10084 | 0 | if (verticalAlign.GetUnit() == eStyleUnit_Enumerated) { |
10085 | 0 | return verticalAlign.GetIntValue(); |
10086 | 0 | } |
10087 | 0 | |
10088 | 0 | return eInvalidVerticalAlign; |
10089 | 0 | } |
10090 | | |
10091 | | /* static */ |
10092 | | void nsFrame::FillCursorInformationFromStyle(const nsStyleUI* ui, |
10093 | | nsIFrame::Cursor& aCursor) |
10094 | 0 | { |
10095 | 0 | aCursor.mCursor = ui->mCursor; |
10096 | 0 | aCursor.mHaveHotspot = false; |
10097 | 0 | aCursor.mLoading = false; |
10098 | 0 | aCursor.mHotspotX = aCursor.mHotspotY = 0.0f; |
10099 | 0 |
|
10100 | 0 | for (const nsCursorImage& item : ui->mCursorImages) { |
10101 | 0 | uint32_t status; |
10102 | 0 | imgRequestProxy* req = item.GetImage(); |
10103 | 0 | if (!req || NS_FAILED(req->GetImageStatus(&status))) { |
10104 | 0 | continue; |
10105 | 0 | } |
10106 | 0 | if (!(status & imgIRequest::STATUS_LOAD_COMPLETE)) { |
10107 | 0 | // If we are falling back because any cursor before is loading, |
10108 | 0 | // let the consumer know. |
10109 | 0 | aCursor.mLoading = true; |
10110 | 0 | } else if (!(status & imgIRequest::STATUS_ERROR)) { |
10111 | 0 | // This is the one we want |
10112 | 0 | req->GetImage(getter_AddRefs(aCursor.mContainer)); |
10113 | 0 | aCursor.mHaveHotspot = item.mHaveHotspot; |
10114 | 0 | aCursor.mHotspotX = item.mHotspotX; |
10115 | 0 | aCursor.mHotspotY = item.mHotspotY; |
10116 | 0 | break; |
10117 | 0 | } |
10118 | 0 | } |
10119 | 0 | } |
10120 | | |
10121 | | NS_IMETHODIMP |
10122 | | nsFrame::RefreshSizeCache(nsBoxLayoutState& aState) |
10123 | 0 | { |
10124 | 0 | // XXXbz this comment needs some rewriting to make sense in the |
10125 | 0 | // post-reflow-branch world. |
10126 | 0 |
|
10127 | 0 | // Ok we need to compute our minimum, preferred, and maximum sizes. |
10128 | 0 | // 1) Maximum size. This is easy. Its infinite unless it is overloaded by CSS. |
10129 | 0 | // 2) Preferred size. This is a little harder. This is the size the block would be |
10130 | 0 | // if it were laid out on an infinite canvas. So we can get this by reflowing |
10131 | 0 | // the block with and INTRINSIC width and height. We can also do a nice optimization |
10132 | 0 | // for incremental reflow. If the reflow is incremental then we can pass a flag to |
10133 | 0 | // have the block compute the preferred width for us! Preferred height can just be |
10134 | 0 | // the minimum height; |
10135 | 0 | // 3) Minimum size. This is a toughy. We can pass the block a flag asking for the max element |
10136 | 0 | // size. That would give us the width. Unfortunately you can only ask for a maxElementSize |
10137 | 0 | // during an incremental reflow. So on other reflows we will just have to use 0. |
10138 | 0 | // The min height on the other hand is fairly easy we need to get the largest |
10139 | 0 | // line height. This can be done with the line iterator. |
10140 | 0 |
|
10141 | 0 | // if we do have a rendering context |
10142 | 0 | gfxContext* rendContext = aState.GetRenderingContext(); |
10143 | 0 | if (rendContext) { |
10144 | 0 | nsPresContext* presContext = aState.PresContext(); |
10145 | 0 |
|
10146 | 0 | // If we don't have any HTML constraints and it's a resize, then nothing in the block |
10147 | 0 | // could have changed, so no refresh is necessary. |
10148 | 0 | nsBoxLayoutMetrics* metrics = BoxMetrics(); |
10149 | 0 | if (!DoesNeedRecalc(metrics->mBlockPrefSize)) |
10150 | 0 | return NS_OK; |
10151 | 0 | |
10152 | 0 | // the rect we plan to size to. |
10153 | 0 | nsRect rect = GetRect(); |
10154 | 0 |
|
10155 | 0 | nsMargin bp(0,0,0,0); |
10156 | 0 | GetXULBorderAndPadding(bp); |
10157 | 0 |
|
10158 | 0 | { |
10159 | 0 | // If we're a container for font size inflation, then shrink |
10160 | 0 | // wrapping inside of us should not apply font size inflation. |
10161 | 0 | AutoMaybeDisableFontInflation an(this); |
10162 | 0 |
|
10163 | 0 | metrics->mBlockPrefSize.width = |
10164 | 0 | GetPrefISize(rendContext) + bp.LeftRight(); |
10165 | 0 | metrics->mBlockMinSize.width = |
10166 | 0 | GetMinISize(rendContext) + bp.LeftRight(); |
10167 | 0 | } |
10168 | 0 |
|
10169 | 0 | // do the nasty. |
10170 | 0 | const WritingMode wm = aState.OuterReflowInput() ? |
10171 | 0 | aState.OuterReflowInput()->GetWritingMode() : GetWritingMode(); |
10172 | 0 | ReflowOutput desiredSize(wm); |
10173 | 0 | BoxReflow(aState, presContext, desiredSize, rendContext, |
10174 | 0 | rect.x, rect.y, |
10175 | 0 | metrics->mBlockPrefSize.width, NS_UNCONSTRAINEDSIZE); |
10176 | 0 |
|
10177 | 0 | metrics->mBlockMinSize.height = 0; |
10178 | 0 | // ok we need the max ascent of the items on the line. So to do this |
10179 | 0 | // ask the block for its line iterator. Get the max ascent. |
10180 | 0 | nsAutoLineIterator lines = GetLineIterator(); |
10181 | 0 | if (lines) |
10182 | 0 | { |
10183 | 0 | metrics->mBlockMinSize.height = 0; |
10184 | 0 | int count = 0; |
10185 | 0 | nsIFrame* firstFrame = nullptr; |
10186 | 0 | int32_t framesOnLine; |
10187 | 0 | nsRect lineBounds; |
10188 | 0 |
|
10189 | 0 | do { |
10190 | 0 | lines->GetLine(count, &firstFrame, &framesOnLine, lineBounds); |
10191 | 0 |
|
10192 | 0 | if (lineBounds.height > metrics->mBlockMinSize.height) |
10193 | 0 | metrics->mBlockMinSize.height = lineBounds.height; |
10194 | 0 |
|
10195 | 0 | count++; |
10196 | 0 | } while(firstFrame); |
10197 | 0 | } else { |
10198 | 0 | metrics->mBlockMinSize.height = desiredSize.Height(); |
10199 | 0 | } |
10200 | 0 |
|
10201 | 0 | metrics->mBlockPrefSize.height = metrics->mBlockMinSize.height; |
10202 | 0 |
|
10203 | 0 | if (desiredSize.BlockStartAscent() == |
10204 | 0 | ReflowOutput::ASK_FOR_BASELINE) { |
10205 | 0 | if (!nsLayoutUtils::GetFirstLineBaseline(wm, this, |
10206 | 0 | &metrics->mBlockAscent)) |
10207 | 0 | metrics->mBlockAscent = GetLogicalBaseline(wm); |
10208 | 0 | } else { |
10209 | 0 | metrics->mBlockAscent = desiredSize.BlockStartAscent(); |
10210 | 0 | } |
10211 | 0 |
|
10212 | | #ifdef DEBUG_adaptor |
10213 | | printf("min=(%d,%d), pref=(%d,%d), ascent=%d\n", metrics->mBlockMinSize.width, |
10214 | | metrics->mBlockMinSize.height, |
10215 | | metrics->mBlockPrefSize.width, |
10216 | | metrics->mBlockPrefSize.height, |
10217 | | metrics->mBlockAscent); |
10218 | | #endif |
10219 | | } |
10220 | 0 |
|
10221 | 0 | return NS_OK; |
10222 | 0 | } |
10223 | | |
10224 | | /* virtual */ nsILineIterator* |
10225 | | nsFrame::GetLineIterator() |
10226 | 0 | { |
10227 | 0 | return nullptr; |
10228 | 0 | } |
10229 | | |
10230 | | nsSize |
10231 | | nsFrame::GetXULPrefSize(nsBoxLayoutState& aState) |
10232 | 0 | { |
10233 | 0 | nsSize size(0,0); |
10234 | 0 | DISPLAY_PREF_SIZE(this, size); |
10235 | 0 | // If the size is cached, and there are no HTML constraints that we might |
10236 | 0 | // be depending on, then we just return the cached size. |
10237 | 0 | nsBoxLayoutMetrics *metrics = BoxMetrics(); |
10238 | 0 | if (!DoesNeedRecalc(metrics->mPrefSize)) { |
10239 | 0 | size = metrics->mPrefSize; |
10240 | 0 | return size; |
10241 | 0 | } |
10242 | 0 | |
10243 | 0 | if (IsXULCollapsed()) |
10244 | 0 | return size; |
10245 | 0 | |
10246 | 0 | // get our size in CSS. |
10247 | 0 | bool widthSet, heightSet; |
10248 | 0 | bool completelyRedefined = nsIFrame::AddXULPrefSize(this, size, widthSet, heightSet); |
10249 | 0 |
|
10250 | 0 | // Refresh our caches with new sizes. |
10251 | 0 | if (!completelyRedefined) { |
10252 | 0 | RefreshSizeCache(aState); |
10253 | 0 | nsSize blockSize = metrics->mBlockPrefSize; |
10254 | 0 |
|
10255 | 0 | // notice we don't need to add our borders or padding |
10256 | 0 | // in. That's because the block did it for us. |
10257 | 0 | if (!widthSet) |
10258 | 0 | size.width = blockSize.width; |
10259 | 0 | if (!heightSet) |
10260 | 0 | size.height = blockSize.height; |
10261 | 0 | } |
10262 | 0 |
|
10263 | 0 | metrics->mPrefSize = size; |
10264 | 0 | return size; |
10265 | 0 | } |
10266 | | |
10267 | | nsSize |
10268 | | nsFrame::GetXULMinSize(nsBoxLayoutState& aState) |
10269 | 0 | { |
10270 | 0 | nsSize size(0,0); |
10271 | 0 | DISPLAY_MIN_SIZE(this, size); |
10272 | 0 | // Don't use the cache if we have HTMLReflowInput constraints --- they might have changed |
10273 | 0 | nsBoxLayoutMetrics *metrics = BoxMetrics(); |
10274 | 0 | if (!DoesNeedRecalc(metrics->mMinSize)) { |
10275 | 0 | size = metrics->mMinSize; |
10276 | 0 | return size; |
10277 | 0 | } |
10278 | 0 | |
10279 | 0 | if (IsXULCollapsed()) |
10280 | 0 | return size; |
10281 | 0 | |
10282 | 0 | // get our size in CSS. |
10283 | 0 | bool widthSet, heightSet; |
10284 | 0 | bool completelyRedefined = |
10285 | 0 | nsIFrame::AddXULMinSize(aState, this, size, widthSet, heightSet); |
10286 | 0 |
|
10287 | 0 | // Refresh our caches with new sizes. |
10288 | 0 | if (!completelyRedefined) { |
10289 | 0 | RefreshSizeCache(aState); |
10290 | 0 | nsSize blockSize = metrics->mBlockMinSize; |
10291 | 0 |
|
10292 | 0 | if (!widthSet) |
10293 | 0 | size.width = blockSize.width; |
10294 | 0 | if (!heightSet) |
10295 | 0 | size.height = blockSize.height; |
10296 | 0 | } |
10297 | 0 |
|
10298 | 0 | metrics->mMinSize = size; |
10299 | 0 | return size; |
10300 | 0 | } |
10301 | | |
10302 | | nsSize |
10303 | | nsFrame::GetXULMaxSize(nsBoxLayoutState& aState) |
10304 | 0 | { |
10305 | 0 | nsSize size(NS_INTRINSICSIZE, NS_INTRINSICSIZE); |
10306 | 0 | DISPLAY_MAX_SIZE(this, size); |
10307 | 0 | // Don't use the cache if we have HTMLReflowInput constraints --- they might have changed |
10308 | 0 | nsBoxLayoutMetrics *metrics = BoxMetrics(); |
10309 | 0 | if (!DoesNeedRecalc(metrics->mMaxSize)) { |
10310 | 0 | size = metrics->mMaxSize; |
10311 | 0 | return size; |
10312 | 0 | } |
10313 | 0 | |
10314 | 0 | if (IsXULCollapsed()) |
10315 | 0 | return size; |
10316 | 0 | |
10317 | 0 | size = nsBox::GetXULMaxSize(aState); |
10318 | 0 | metrics->mMaxSize = size; |
10319 | 0 |
|
10320 | 0 | return size; |
10321 | 0 | } |
10322 | | |
10323 | | nscoord |
10324 | | nsFrame::GetXULFlex() |
10325 | 0 | { |
10326 | 0 | nsBoxLayoutMetrics *metrics = BoxMetrics(); |
10327 | 0 | if (!DoesNeedRecalc(metrics->mFlex)) |
10328 | 0 | return metrics->mFlex; |
10329 | 0 | |
10330 | 0 | metrics->mFlex = nsBox::GetXULFlex(); |
10331 | 0 |
|
10332 | 0 | return metrics->mFlex; |
10333 | 0 | } |
10334 | | |
10335 | | nscoord |
10336 | | nsFrame::GetXULBoxAscent(nsBoxLayoutState& aState) |
10337 | 0 | { |
10338 | 0 | nsBoxLayoutMetrics *metrics = BoxMetrics(); |
10339 | 0 | if (!DoesNeedRecalc(metrics->mAscent)) |
10340 | 0 | return metrics->mAscent; |
10341 | 0 | |
10342 | 0 | if (IsXULCollapsed()) { |
10343 | 0 | metrics->mAscent = 0; |
10344 | 0 | } else { |
10345 | 0 | // Refresh our caches with new sizes. |
10346 | 0 | RefreshSizeCache(aState); |
10347 | 0 | metrics->mAscent = metrics->mBlockAscent; |
10348 | 0 | } |
10349 | 0 |
|
10350 | 0 | return metrics->mAscent; |
10351 | 0 | } |
10352 | | |
10353 | | nsresult |
10354 | | nsFrame::DoXULLayout(nsBoxLayoutState& aState) |
10355 | 0 | { |
10356 | 0 | nsRect ourRect(mRect); |
10357 | 0 |
|
10358 | 0 | gfxContext* rendContext = aState.GetRenderingContext(); |
10359 | 0 | nsPresContext* presContext = aState.PresContext(); |
10360 | 0 | WritingMode ourWM = GetWritingMode(); |
10361 | 0 | const WritingMode outerWM = aState.OuterReflowInput() ? |
10362 | 0 | aState.OuterReflowInput()->GetWritingMode() : ourWM; |
10363 | 0 | ReflowOutput desiredSize(outerWM); |
10364 | 0 | LogicalSize ourSize = GetLogicalSize(outerWM); |
10365 | 0 |
|
10366 | 0 | if (rendContext) { |
10367 | 0 |
|
10368 | 0 | BoxReflow(aState, presContext, desiredSize, rendContext, |
10369 | 0 | ourRect.x, ourRect.y, ourRect.width, ourRect.height); |
10370 | 0 |
|
10371 | 0 | if (IsXULCollapsed()) { |
10372 | 0 | SetSize(nsSize(0, 0)); |
10373 | 0 | } else { |
10374 | 0 |
|
10375 | 0 | // if our child needs to be bigger. This might happend with |
10376 | 0 | // wrapping text. There is no way to predict its height until we |
10377 | 0 | // reflow it. Now that we know the height reshuffle upward. |
10378 | 0 | if (desiredSize.ISize(outerWM) > ourSize.ISize(outerWM) || |
10379 | 0 | desiredSize.BSize(outerWM) > ourSize.BSize(outerWM)) { |
10380 | 0 |
|
10381 | | #ifdef DEBUG_GROW |
10382 | | XULDumpBox(stdout); |
10383 | | printf(" GREW from (%d,%d) -> (%d,%d)\n", |
10384 | | ourSize.ISize(outerWM), ourSize.BSize(outerWM), |
10385 | | desiredSize.ISize(outerWM), desiredSize.BSize(outerWM)); |
10386 | | #endif |
10387 | |
|
10388 | 0 | if (desiredSize.ISize(outerWM) > ourSize.ISize(outerWM)) { |
10389 | 0 | ourSize.ISize(outerWM) = desiredSize.ISize(outerWM); |
10390 | 0 | } |
10391 | 0 |
|
10392 | 0 | if (desiredSize.BSize(outerWM) > ourSize.BSize(outerWM)) { |
10393 | 0 | ourSize.BSize(outerWM) = desiredSize.BSize(outerWM); |
10394 | 0 | } |
10395 | 0 | } |
10396 | 0 |
|
10397 | 0 | // ensure our size is what we think is should be. Someone could have |
10398 | 0 | // reset the frame to be smaller or something dumb like that. |
10399 | 0 | SetSize(ourSize.ConvertTo(ourWM, outerWM)); |
10400 | 0 | } |
10401 | 0 | } |
10402 | 0 |
|
10403 | 0 | // Should we do this if IsXULCollapsed() is true? |
10404 | 0 | LogicalSize size(GetLogicalSize(outerWM)); |
10405 | 0 | desiredSize.ISize(outerWM) = size.ISize(outerWM); |
10406 | 0 | desiredSize.BSize(outerWM) = size.BSize(outerWM); |
10407 | 0 | desiredSize.UnionOverflowAreasWithDesiredBounds(); |
10408 | 0 |
|
10409 | 0 | if (HasAbsolutelyPositionedChildren()) { |
10410 | 0 | // Set up a |reflowInput| to pass into ReflowAbsoluteFrames |
10411 | 0 | ReflowInput reflowInput(aState.PresContext(), this, |
10412 | 0 | aState.GetRenderingContext(), |
10413 | 0 | LogicalSize(ourWM, ISize(), |
10414 | 0 | NS_UNCONSTRAINEDSIZE), |
10415 | 0 | ReflowInput::DUMMY_PARENT_REFLOW_STATE); |
10416 | 0 |
|
10417 | 0 | AddStateBits(NS_FRAME_IN_REFLOW); |
10418 | 0 | // Set up a |reflowStatus| to pass into ReflowAbsoluteFrames |
10419 | 0 | // (just a dummy value; hopefully that's OK) |
10420 | 0 | nsReflowStatus reflowStatus; |
10421 | 0 | ReflowAbsoluteFrames(aState.PresContext(), desiredSize, |
10422 | 0 | reflowInput, reflowStatus); |
10423 | 0 | RemoveStateBits(NS_FRAME_IN_REFLOW); |
10424 | 0 | } |
10425 | 0 |
|
10426 | 0 | nsSize oldSize(ourRect.Size()); |
10427 | 0 | FinishAndStoreOverflow(desiredSize.mOverflowAreas, |
10428 | 0 | size.GetPhysicalSize(outerWM), &oldSize); |
10429 | 0 |
|
10430 | 0 | SyncLayout(aState); |
10431 | 0 |
|
10432 | 0 | return NS_OK; |
10433 | 0 | } |
10434 | | |
10435 | | void |
10436 | | nsFrame::BoxReflow(nsBoxLayoutState& aState, |
10437 | | nsPresContext* aPresContext, |
10438 | | ReflowOutput& aDesiredSize, |
10439 | | gfxContext* aRenderingContext, |
10440 | | nscoord aX, |
10441 | | nscoord aY, |
10442 | | nscoord aWidth, |
10443 | | nscoord aHeight, |
10444 | | bool aMoveFrame) |
10445 | 0 | { |
10446 | 0 | DO_GLOBAL_REFLOW_COUNT("nsBoxToBlockAdaptor"); |
10447 | 0 |
|
10448 | | #ifdef DEBUG_REFLOW |
10449 | | nsAdaptorAddIndents(); |
10450 | | printf("Reflowing: "); |
10451 | | nsFrame::ListTag(stdout, mFrame); |
10452 | | printf("\n"); |
10453 | | gIndent2++; |
10454 | | #endif |
10455 | |
|
10456 | 0 | nsBoxLayoutMetrics* metrics = BoxMetrics(); |
10457 | 0 | if (MOZ_UNLIKELY(!metrics)) { |
10458 | 0 | // Can't proceed without BoxMetrics. This should only happen if something |
10459 | 0 | // is seriously broken, e.g. if we try to do XUL layout on a non-XUL frame. |
10460 | 0 | // (If this is a content process, we'll abort even in release builds, |
10461 | 0 | // because XUL layout mixup is extra surprising in content, and aborts are |
10462 | 0 | // less catastrophic in content vs. in chrome.) |
10463 | 0 | MOZ_RELEASE_ASSERT(!XRE_IsContentProcess(), |
10464 | 0 | "Starting XUL BoxReflow w/o BoxMetrics (in content)?"); |
10465 | 0 | MOZ_ASSERT_UNREACHABLE("Starting XUL BoxReflow w/o BoxMetrics?"); |
10466 | 0 | return; |
10467 | 0 | } |
10468 | 0 | |
10469 | 0 | nsReflowStatus status; |
10470 | 0 | WritingMode wm = aDesiredSize.GetWritingMode(); |
10471 | 0 |
|
10472 | 0 | bool needsReflow = NS_SUBTREE_DIRTY(this); |
10473 | 0 |
|
10474 | 0 | // if we don't need a reflow then |
10475 | 0 | // lets see if we are already that size. Yes? then don't even reflow. We are done. |
10476 | 0 | if (!needsReflow) { |
10477 | 0 |
|
10478 | 0 | if (aWidth != NS_INTRINSICSIZE && aHeight != NS_INTRINSICSIZE) { |
10479 | 0 |
|
10480 | 0 | // if the new calculated size has a 0 width or a 0 height |
10481 | 0 | if ((metrics->mLastSize.width == 0 || metrics->mLastSize.height == 0) && (aWidth == 0 || aHeight == 0)) { |
10482 | 0 | needsReflow = false; |
10483 | 0 | aDesiredSize.Width() = aWidth; |
10484 | 0 | aDesiredSize.Height() = aHeight; |
10485 | 0 | SetSize(aDesiredSize.Size(wm).ConvertTo(GetWritingMode(), wm)); |
10486 | 0 | } else { |
10487 | 0 | aDesiredSize.Width() = metrics->mLastSize.width; |
10488 | 0 | aDesiredSize.Height() = metrics->mLastSize.height; |
10489 | 0 |
|
10490 | 0 | // remove the margin. The rect of our child does not include it but our calculated size does. |
10491 | 0 | // don't reflow if we are already the right size |
10492 | 0 | if (metrics->mLastSize.width == aWidth && metrics->mLastSize.height == aHeight) |
10493 | 0 | needsReflow = false; |
10494 | 0 | else |
10495 | 0 | needsReflow = true; |
10496 | 0 |
|
10497 | 0 | } |
10498 | 0 | } else { |
10499 | 0 | // if the width or height are intrinsic alway reflow because |
10500 | 0 | // we don't know what it should be. |
10501 | 0 | needsReflow = true; |
10502 | 0 | } |
10503 | 0 | } |
10504 | 0 |
|
10505 | 0 | // ok now reflow the child into the spacers calculated space |
10506 | 0 | if (needsReflow) { |
10507 | 0 |
|
10508 | 0 | aDesiredSize.ClearSize(); |
10509 | 0 |
|
10510 | 0 | // create a reflow state to tell our child to flow at the given size. |
10511 | 0 |
|
10512 | 0 | // Construct a bogus parent reflow state so that there's a usable |
10513 | 0 | // containing block reflow state. |
10514 | 0 | nsMargin margin(0,0,0,0); |
10515 | 0 | GetXULMargin(margin); |
10516 | 0 |
|
10517 | 0 | nsSize parentSize(aWidth, aHeight); |
10518 | 0 | if (parentSize.height != NS_INTRINSICSIZE) |
10519 | 0 | parentSize.height += margin.TopBottom(); |
10520 | 0 | if (parentSize.width != NS_INTRINSICSIZE) |
10521 | 0 | parentSize.width += margin.LeftRight(); |
10522 | 0 |
|
10523 | 0 | nsIFrame *parentFrame = GetParent(); |
10524 | 0 | WritingMode parentWM = parentFrame->GetWritingMode(); |
10525 | 0 | ReflowInput |
10526 | 0 | parentReflowInput(aPresContext, parentFrame, aRenderingContext, |
10527 | 0 | LogicalSize(parentWM, parentSize), |
10528 | 0 | ReflowInput::DUMMY_PARENT_REFLOW_STATE); |
10529 | 0 |
|
10530 | 0 | // This may not do very much useful, but it's probably worth trying. |
10531 | 0 | if (parentSize.width != NS_INTRINSICSIZE) |
10532 | 0 | parentReflowInput.SetComputedWidth(std::max(parentSize.width, 0)); |
10533 | 0 | if (parentSize.height != NS_INTRINSICSIZE) |
10534 | 0 | parentReflowInput.SetComputedHeight(std::max(parentSize.height, 0)); |
10535 | 0 | parentReflowInput.ComputedPhysicalMargin().SizeTo(0, 0, 0, 0); |
10536 | 0 | // XXX use box methods |
10537 | 0 | parentFrame->GetXULPadding(parentReflowInput.ComputedPhysicalPadding()); |
10538 | 0 | parentFrame->GetXULBorder(parentReflowInput.ComputedPhysicalBorderPadding()); |
10539 | 0 | parentReflowInput.ComputedPhysicalBorderPadding() += |
10540 | 0 | parentReflowInput.ComputedPhysicalPadding(); |
10541 | 0 |
|
10542 | 0 | // Construct the parent chain manually since constructing it normally |
10543 | 0 | // messes up dimensions. |
10544 | 0 | const ReflowInput *outerReflowInput = aState.OuterReflowInput(); |
10545 | 0 | NS_ASSERTION(!outerReflowInput || outerReflowInput->mFrame != this, |
10546 | 0 | "in and out of XUL on a single frame?"); |
10547 | 0 | const ReflowInput* parentRI; |
10548 | 0 | if (outerReflowInput && outerReflowInput->mFrame == parentFrame) { |
10549 | 0 | // We're a frame (such as a text control frame) that jumps into |
10550 | 0 | // box reflow and then straight out of it on the child frame. |
10551 | 0 | // This means we actually have a real parent reflow state. |
10552 | 0 | // nsLayoutUtils::InflationMinFontSizeFor used to need this to be |
10553 | 0 | // linked up correctly for text control frames, so do so here). |
10554 | 0 | parentRI = outerReflowInput; |
10555 | 0 | } else { |
10556 | 0 | parentRI = &parentReflowInput; |
10557 | 0 | } |
10558 | 0 |
|
10559 | 0 | // XXX Is it OK that this reflow state has only one ancestor? |
10560 | 0 | // (It used to have a bogus parent, skipping all the boxes). |
10561 | 0 | WritingMode wm = GetWritingMode(); |
10562 | 0 | LogicalSize logicalSize(wm, nsSize(aWidth, aHeight)); |
10563 | 0 | logicalSize.BSize(wm) = NS_INTRINSICSIZE; |
10564 | 0 | ReflowInput reflowInput(aPresContext, *parentRI, this, |
10565 | 0 | logicalSize, nullptr, |
10566 | 0 | ReflowInput::DUMMY_PARENT_REFLOW_STATE); |
10567 | 0 |
|
10568 | 0 | // XXX_jwir3: This is somewhat fishy. If this is actually changing the value |
10569 | 0 | // here (which it might be), then we should make sure that it's |
10570 | 0 | // correct the first time around, rather than changing it later. |
10571 | 0 | reflowInput.mCBReflowInput = parentRI; |
10572 | 0 |
|
10573 | 0 | reflowInput.mReflowDepth = aState.GetReflowDepth(); |
10574 | 0 |
|
10575 | 0 | // mComputedWidth and mComputedHeight are content-box, not |
10576 | 0 | // border-box |
10577 | 0 | if (aWidth != NS_INTRINSICSIZE) { |
10578 | 0 | nscoord computedWidth = |
10579 | 0 | aWidth - reflowInput.ComputedPhysicalBorderPadding().LeftRight(); |
10580 | 0 | computedWidth = std::max(computedWidth, 0); |
10581 | 0 | reflowInput.SetComputedWidth(computedWidth); |
10582 | 0 | } |
10583 | 0 |
|
10584 | 0 | // Most child frames of box frames (e.g. subdocument or scroll frames) |
10585 | 0 | // need to be constrained to the provided size and overflow as necessary. |
10586 | 0 | // The one exception are block frames, because we need to know their |
10587 | 0 | // natural height excluding any overflow area which may be caused by |
10588 | 0 | // various CSS effects such as shadow or outline. |
10589 | 0 | if (!IsFrameOfType(eBlockFrame)) { |
10590 | 0 | if (aHeight != NS_INTRINSICSIZE) { |
10591 | 0 | nscoord computedHeight = |
10592 | 0 | aHeight - reflowInput.ComputedPhysicalBorderPadding().TopBottom(); |
10593 | 0 | computedHeight = std::max(computedHeight, 0); |
10594 | 0 | reflowInput.SetComputedHeight(computedHeight); |
10595 | 0 | } else { |
10596 | 0 | reflowInput.SetComputedHeight( |
10597 | 0 | ComputeSize(aRenderingContext, wm, |
10598 | 0 | logicalSize, |
10599 | 0 | logicalSize.ISize(wm), |
10600 | 0 | reflowInput.ComputedLogicalMargin().Size(wm), |
10601 | 0 | reflowInput.ComputedLogicalBorderPadding().Size(wm) - |
10602 | 0 | reflowInput.ComputedLogicalPadding().Size(wm), |
10603 | 0 | reflowInput.ComputedLogicalPadding().Size(wm), |
10604 | 0 | ComputeSizeFlags::eDefault).Height(wm)); |
10605 | 0 | } |
10606 | 0 | } |
10607 | 0 |
|
10608 | 0 | // Box layout calls SetRect before XULLayout, whereas non-box layout |
10609 | 0 | // calls SetRect after Reflow. |
10610 | 0 | // XXX Perhaps we should be doing this by twiddling the rect back to |
10611 | 0 | // mLastSize before calling Reflow and then switching it back, but |
10612 | 0 | // However, mLastSize can also be the size passed to BoxReflow by |
10613 | 0 | // RefreshSizeCache, so that doesn't really make sense. |
10614 | 0 | if (metrics->mLastSize.width != aWidth) { |
10615 | 0 | reflowInput.SetHResize(true); |
10616 | 0 |
|
10617 | 0 | // When font size inflation is enabled, a horizontal resize |
10618 | 0 | // requires a full reflow. See ReflowInput::InitResizeFlags |
10619 | 0 | // for more details. |
10620 | 0 | if (nsLayoutUtils::FontSizeInflationEnabled(aPresContext)) { |
10621 | 0 | AddStateBits(NS_FRAME_IS_DIRTY); |
10622 | 0 | } |
10623 | 0 | } |
10624 | 0 | if (metrics->mLastSize.height != aHeight) { |
10625 | 0 | reflowInput.SetVResize(true); |
10626 | 0 | } |
10627 | 0 |
|
10628 | | #ifdef DEBUG_REFLOW |
10629 | | nsAdaptorAddIndents(); |
10630 | | printf("Size=(%d,%d)\n",reflowInput.ComputedWidth(), |
10631 | | reflowInput.ComputedHeight()); |
10632 | | nsAdaptorAddIndents(); |
10633 | | nsAdaptorPrintReason(reflowInput); |
10634 | | printf("\n"); |
10635 | | #endif |
10636 | |
|
10637 | 0 | // place the child and reflow |
10638 | 0 |
|
10639 | 0 | Reflow(aPresContext, aDesiredSize, reflowInput, status); |
10640 | 0 |
|
10641 | 0 | NS_ASSERTION(status.IsComplete(), "bad status"); |
10642 | 0 |
|
10643 | 0 | uint32_t layoutFlags = aState.LayoutFlags(); |
10644 | 0 | nsContainerFrame::FinishReflowChild(this, aPresContext, aDesiredSize, |
10645 | 0 | &reflowInput, aX, aY, layoutFlags | NS_FRAME_NO_MOVE_FRAME); |
10646 | 0 |
|
10647 | 0 | // Save the ascent. (bug 103925) |
10648 | 0 | if (IsXULCollapsed()) { |
10649 | 0 | metrics->mAscent = 0; |
10650 | 0 | } else { |
10651 | 0 | if (aDesiredSize.BlockStartAscent() == |
10652 | 0 | ReflowOutput::ASK_FOR_BASELINE) { |
10653 | 0 | if (!nsLayoutUtils::GetFirstLineBaseline(wm, this, &metrics->mAscent)) |
10654 | 0 | metrics->mAscent = GetLogicalBaseline(wm); |
10655 | 0 | } else |
10656 | 0 | metrics->mAscent = aDesiredSize.BlockStartAscent(); |
10657 | 0 | } |
10658 | 0 |
|
10659 | 0 | } else { |
10660 | 0 | aDesiredSize.SetBlockStartAscent(metrics->mBlockAscent); |
10661 | 0 | } |
10662 | 0 |
|
10663 | | #ifdef DEBUG_REFLOW |
10664 | | if (aHeight != NS_INTRINSICSIZE && aDesiredSize.Height() != aHeight) |
10665 | | { |
10666 | | nsAdaptorAddIndents(); |
10667 | | printf("*****got taller!*****\n"); |
10668 | | |
10669 | | } |
10670 | | if (aWidth != NS_INTRINSICSIZE && aDesiredSize.Width() != aWidth) |
10671 | | { |
10672 | | nsAdaptorAddIndents(); |
10673 | | printf("*****got wider!******\n"); |
10674 | | |
10675 | | } |
10676 | | #endif |
10677 | |
|
10678 | 0 | if (aWidth == NS_INTRINSICSIZE) |
10679 | 0 | aWidth = aDesiredSize.Width(); |
10680 | 0 |
|
10681 | 0 | if (aHeight == NS_INTRINSICSIZE) |
10682 | 0 | aHeight = aDesiredSize.Height(); |
10683 | 0 |
|
10684 | 0 | metrics->mLastSize.width = aDesiredSize.Width(); |
10685 | 0 | metrics->mLastSize.height = aDesiredSize.Height(); |
10686 | 0 |
|
10687 | | #ifdef DEBUG_REFLOW |
10688 | | gIndent2--; |
10689 | | #endif |
10690 | | } |
10691 | | |
10692 | | nsBoxLayoutMetrics* |
10693 | | nsFrame::BoxMetrics() const |
10694 | 0 | { |
10695 | 0 | nsBoxLayoutMetrics* metrics = GetProperty(BoxMetricsProperty()); |
10696 | 0 | NS_ASSERTION(metrics, "A box layout method was called but InitBoxMetrics was never called"); |
10697 | 0 | return metrics; |
10698 | 0 | } |
10699 | | |
10700 | | void |
10701 | | nsIFrame::UpdateStyleOfChildAnonBox(nsIFrame* aChildFrame, |
10702 | | ServoRestyleState& aRestyleState) |
10703 | 0 | { |
10704 | | #ifdef DEBUG |
10705 | | nsIFrame* parent = aChildFrame->GetInFlowParent(); |
10706 | | if (aChildFrame->IsTableFrame()) { |
10707 | | parent = parent->GetParent(); |
10708 | | } |
10709 | | if (parent->IsLineFrame()) { |
10710 | | parent = parent->GetParent(); |
10711 | | } |
10712 | | MOZ_ASSERT(nsLayoutUtils::FirstContinuationOrIBSplitSibling(parent) == this, |
10713 | | "This should only be used for children!"); |
10714 | | #endif // DEBUG |
10715 | 0 | MOZ_ASSERT(!GetContent() || !aChildFrame->GetContent() || |
10716 | 0 | aChildFrame->GetContent() == GetContent(), |
10717 | 0 | "What content node is it a frame for?"); |
10718 | 0 | MOZ_ASSERT(!aChildFrame->GetPrevContinuation(), |
10719 | 0 | "Only first continuations should end up here"); |
10720 | 0 |
|
10721 | 0 | // We could force the caller to pass in the pseudo, since some callers know it |
10722 | 0 | // statically... But this API is a bit nicer. |
10723 | 0 | nsAtom* pseudo = aChildFrame->Style()->GetPseudo(); |
10724 | 0 | MOZ_ASSERT(nsCSSAnonBoxes::IsAnonBox(pseudo), "Child is not an anon box?"); |
10725 | 0 | MOZ_ASSERT(!nsCSSAnonBoxes::IsNonInheritingAnonBox(pseudo), |
10726 | 0 | "Why did the caller bother calling us?"); |
10727 | 0 |
|
10728 | 0 | // Anon boxes inherit from their parent; that's us. |
10729 | 0 | RefPtr<ComputedStyle> newContext = |
10730 | 0 | aRestyleState.StyleSet().ResolveInheritingAnonymousBoxStyle(pseudo, Style()); |
10731 | 0 |
|
10732 | 0 | nsChangeHint childHint = |
10733 | 0 | UpdateStyleOfOwnedChildFrame(aChildFrame, newContext, aRestyleState); |
10734 | 0 |
|
10735 | 0 | // Now that we've updated the style on aChildFrame, check whether it itself |
10736 | 0 | // has anon boxes to deal with. |
10737 | 0 | ServoRestyleState childrenState( |
10738 | 0 | *aChildFrame, aRestyleState, childHint, ServoRestyleState::Type::InFlow); |
10739 | 0 | aChildFrame->UpdateStyleOfOwnedAnonBoxes(childrenState); |
10740 | 0 |
|
10741 | 0 | // Assuming anon boxes don't have ::backdrop associated with them... if that |
10742 | 0 | // ever changes, we'd need to handle that here, like we do in |
10743 | 0 | // RestyleManager::ProcessPostTraversal |
10744 | 0 |
|
10745 | 0 | // We do need to handle block pseudo-elements here, though. Especially list |
10746 | 0 | // bullets. |
10747 | 0 | if (aChildFrame->IsFrameOfType(nsIFrame::eBlockFrame)) { |
10748 | 0 | auto block = static_cast<nsBlockFrame*>(aChildFrame); |
10749 | 0 | block->UpdatePseudoElementStyles(childrenState); |
10750 | 0 | } |
10751 | 0 | } |
10752 | | |
10753 | | /* static */ nsChangeHint |
10754 | | nsIFrame::UpdateStyleOfOwnedChildFrame( |
10755 | | nsIFrame* aChildFrame, |
10756 | | ComputedStyle* aNewComputedStyle, |
10757 | | ServoRestyleState& aRestyleState, |
10758 | | const Maybe<ComputedStyle*>& aContinuationComputedStyle) |
10759 | 0 | { |
10760 | 0 | MOZ_ASSERT(!aChildFrame->GetAdditionalComputedStyle(0), |
10761 | 0 | "We don't handle additional styles here"); |
10762 | 0 |
|
10763 | 0 | // Figure out whether we have an actual change. It's important that we do |
10764 | 0 | // this, for several reasons: |
10765 | 0 | // |
10766 | 0 | // 1) Even if all the child's changes are due to properties it inherits from |
10767 | 0 | // us, it's possible that no one ever asked us for those style structs and |
10768 | 0 | // hence changes to them aren't reflected in the changes handled at all. |
10769 | 0 | // |
10770 | 0 | // 2) Content can change stylesheets that change the styles of pseudos, and |
10771 | 0 | // extensions can add/remove stylesheets that change the styles of |
10772 | 0 | // anonymous boxes directly. |
10773 | 0 | uint32_t equalStructs; // Not used, actually. |
10774 | 0 | nsChangeHint childHint = |
10775 | 0 | aChildFrame->Style()->CalcStyleDifference(aNewComputedStyle, &equalStructs); |
10776 | 0 |
|
10777 | 0 | // CalcStyleDifference will handle caching structs on the new style, but only |
10778 | 0 | // if we're not on a style worker thread. |
10779 | 0 | MOZ_ASSERT(!ServoStyleSet::IsInServoTraversal(), |
10780 | 0 | "if we can get in here from style worker threads, then we need " |
10781 | 0 | "a ResolveSameStructsAs call to ensure structs are cached on " |
10782 | 0 | "aNewComputedStyle"); |
10783 | 0 |
|
10784 | 0 | // If aChildFrame is out of flow, then aRestyleState's "changes handled by the |
10785 | 0 | // parent" doesn't apply to it, because it may have some other parent in the |
10786 | 0 | // frame tree. |
10787 | 0 | if (!aChildFrame->HasAnyStateBits(NS_FRAME_OUT_OF_FLOW)) { |
10788 | 0 | childHint = NS_RemoveSubsumedHints( |
10789 | 0 | childHint, aRestyleState.ChangesHandledFor(aChildFrame)); |
10790 | 0 | } |
10791 | 0 | if (childHint) { |
10792 | 0 | if (childHint & nsChangeHint_ReconstructFrame) { |
10793 | 0 | // If we generate a reconstruct here, remove any non-reconstruct hints we |
10794 | 0 | // may have already generated for this content. |
10795 | 0 | aRestyleState.ChangeList().PopChangesForContent( |
10796 | 0 | aChildFrame->GetContent()); |
10797 | 0 | } |
10798 | 0 | aRestyleState.ChangeList().AppendChange( |
10799 | 0 | aChildFrame, aChildFrame->GetContent(), childHint); |
10800 | 0 | } |
10801 | 0 |
|
10802 | 0 | aChildFrame->SetComputedStyle(aNewComputedStyle); |
10803 | 0 | ComputedStyle* continuationStyle = |
10804 | 0 | aContinuationComputedStyle ? *aContinuationComputedStyle : aNewComputedStyle; |
10805 | 0 | for (nsIFrame* kid = aChildFrame->GetNextContinuation(); |
10806 | 0 | kid; |
10807 | 0 | kid = kid->GetNextContinuation()) { |
10808 | 0 | MOZ_ASSERT(!kid->GetAdditionalComputedStyle(0)); |
10809 | 0 | kid->SetComputedStyle(continuationStyle); |
10810 | 0 | } |
10811 | 0 |
|
10812 | 0 | return childHint; |
10813 | 0 | } |
10814 | | |
10815 | | /* static */ void |
10816 | | nsIFrame::AddInPopupStateBitToDescendants(nsIFrame* aFrame) |
10817 | 0 | { |
10818 | 0 | if (!aFrame->HasAnyStateBits(NS_FRAME_IN_POPUP) && |
10819 | 0 | aFrame->TrackingVisibility()) { |
10820 | 0 | // Assume all frames in popups are visible. |
10821 | 0 | aFrame->IncApproximateVisibleCount(); |
10822 | 0 | } |
10823 | 0 |
|
10824 | 0 | aFrame->AddStateBits(NS_FRAME_IN_POPUP); |
10825 | 0 |
|
10826 | 0 | AutoTArray<nsIFrame::ChildList,4> childListArray; |
10827 | 0 | aFrame->GetCrossDocChildLists(&childListArray); |
10828 | 0 |
|
10829 | 0 | nsIFrame::ChildListArrayIterator lists(childListArray); |
10830 | 0 | for (; !lists.IsDone(); lists.Next()) { |
10831 | 0 | nsFrameList::Enumerator childFrames(lists.CurrentList()); |
10832 | 0 | for (; !childFrames.AtEnd(); childFrames.Next()) { |
10833 | 0 | AddInPopupStateBitToDescendants(childFrames.get()); |
10834 | 0 | } |
10835 | 0 | } |
10836 | 0 | } |
10837 | | |
10838 | | /* static */ void |
10839 | | nsIFrame::RemoveInPopupStateBitFromDescendants(nsIFrame* aFrame) |
10840 | 0 | { |
10841 | 0 | if (!aFrame->HasAnyStateBits(NS_FRAME_IN_POPUP) || |
10842 | 0 | nsLayoutUtils::IsPopup(aFrame)) { |
10843 | 0 | return; |
10844 | 0 | } |
10845 | 0 | |
10846 | 0 | aFrame->RemoveStateBits(NS_FRAME_IN_POPUP); |
10847 | 0 |
|
10848 | 0 | if (aFrame->TrackingVisibility()) { |
10849 | 0 | // We assume all frames in popups are visible, so this decrement balances |
10850 | 0 | // out the increment in AddInPopupStateBitToDescendants above. |
10851 | 0 | aFrame->DecApproximateVisibleCount(); |
10852 | 0 | } |
10853 | 0 |
|
10854 | 0 | AutoTArray<nsIFrame::ChildList,4> childListArray; |
10855 | 0 | aFrame->GetCrossDocChildLists(&childListArray); |
10856 | 0 |
|
10857 | 0 | nsIFrame::ChildListArrayIterator lists(childListArray); |
10858 | 0 | for (; !lists.IsDone(); lists.Next()) { |
10859 | 0 | nsFrameList::Enumerator childFrames(lists.CurrentList()); |
10860 | 0 | for (; !childFrames.AtEnd(); childFrames.Next()) { |
10861 | 0 | RemoveInPopupStateBitFromDescendants(childFrames.get()); |
10862 | 0 | } |
10863 | 0 | } |
10864 | 0 | } |
10865 | | |
10866 | | void |
10867 | | nsIFrame::SetParent(nsContainerFrame* aParent) |
10868 | 0 | { |
10869 | 0 | // If our parent is a wrapper anon box, our new parent should be too. We |
10870 | 0 | // _can_ change parent if our parent is a wrapper anon box, because some |
10871 | 0 | // wrapper anon boxes can have continuations. |
10872 | 0 | MOZ_ASSERT_IF(ParentIsWrapperAnonBox(), |
10873 | 0 | aParent->Style()->IsInheritingAnonBox()); |
10874 | 0 |
|
10875 | 0 | // Note that the current mParent may already be destroyed at this point. |
10876 | 0 | mParent = aParent; |
10877 | 0 | MOZ_DIAGNOSTIC_ASSERT(!mParent || PresShell() == mParent->PresShell()); |
10878 | 0 | if (::IsXULBoxWrapped(this)) { |
10879 | 0 | ::InitBoxMetrics(this, true); |
10880 | 0 | } else { |
10881 | 0 | // We could call Properties().Delete(BoxMetricsProperty()); here but |
10882 | 0 | // that's kind of slow and re-parenting in such a way that we were |
10883 | 0 | // IsXULBoxWrapped() before but not now should be very rare, so we'll just |
10884 | 0 | // keep this unused frame property until this frame dies instead. |
10885 | 0 | } |
10886 | 0 |
|
10887 | 0 | if (GetStateBits() & (NS_FRAME_HAS_VIEW | NS_FRAME_HAS_CHILD_WITH_VIEW)) { |
10888 | 0 | for (nsIFrame* f = aParent; |
10889 | 0 | f && !(f->GetStateBits() & NS_FRAME_HAS_CHILD_WITH_VIEW); |
10890 | 0 | f = f->GetParent()) { |
10891 | 0 | f->AddStateBits(NS_FRAME_HAS_CHILD_WITH_VIEW); |
10892 | 0 | } |
10893 | 0 | } |
10894 | 0 |
|
10895 | 0 | if (HasAnyStateBits(NS_FRAME_CONTAINS_RELATIVE_BSIZE)) { |
10896 | 0 | for (nsIFrame* f = aParent; f; f = f->GetParent()) { |
10897 | 0 | if (f->HasAnyStateBits(NS_FRAME_CONTAINS_RELATIVE_BSIZE)) { |
10898 | 0 | break; |
10899 | 0 | } |
10900 | 0 | f->AddStateBits(NS_FRAME_CONTAINS_RELATIVE_BSIZE); |
10901 | 0 | } |
10902 | 0 | } |
10903 | 0 |
|
10904 | 0 | if (HasAnyStateBits(NS_FRAME_DESCENDANT_INTRINSIC_ISIZE_DEPENDS_ON_BSIZE)) { |
10905 | 0 | for (nsIFrame* f = aParent; f; f = f->GetParent()) { |
10906 | 0 | if (f->HasAnyStateBits(NS_FRAME_DESCENDANT_INTRINSIC_ISIZE_DEPENDS_ON_BSIZE)) { |
10907 | 0 | break; |
10908 | 0 | } |
10909 | 0 | f->AddStateBits(NS_FRAME_DESCENDANT_INTRINSIC_ISIZE_DEPENDS_ON_BSIZE); |
10910 | 0 | } |
10911 | 0 | } |
10912 | 0 |
|
10913 | 0 | if (HasInvalidFrameInSubtree()) { |
10914 | 0 | for (nsIFrame* f = aParent; |
10915 | 0 | f && !f->HasAnyStateBits(NS_FRAME_DESCENDANT_NEEDS_PAINT | NS_FRAME_IS_NONDISPLAY); |
10916 | 0 | f = nsLayoutUtils::GetCrossDocParentFrame(f)) { |
10917 | 0 | f->AddStateBits(NS_FRAME_DESCENDANT_NEEDS_PAINT); |
10918 | 0 | } |
10919 | 0 | } |
10920 | 0 |
|
10921 | 0 | if (aParent->HasAnyStateBits(NS_FRAME_IN_POPUP)) { |
10922 | 0 | AddInPopupStateBitToDescendants(this); |
10923 | 0 | } else { |
10924 | 0 | RemoveInPopupStateBitFromDescendants(this); |
10925 | 0 | } |
10926 | 0 |
|
10927 | 0 | // If our new parent only has invalid children, then we just invalidate |
10928 | 0 | // ourselves too. This is probably faster than clearing the flag all |
10929 | 0 | // the way up the frame tree. |
10930 | 0 | if (aParent->HasAnyStateBits(NS_FRAME_ALL_DESCENDANTS_NEED_PAINT)) { |
10931 | 0 | InvalidateFrame(); |
10932 | 0 | } else { |
10933 | 0 | SchedulePaint(); |
10934 | 0 | } |
10935 | 0 | } |
10936 | | |
10937 | | void |
10938 | | nsIFrame::CreateOwnLayerIfNeeded(nsDisplayListBuilder* aBuilder, |
10939 | | nsDisplayList* aList, |
10940 | | bool* aCreatedContainerItem) |
10941 | 0 | { |
10942 | 0 | if (GetContent() && |
10943 | 0 | GetContent()->IsXULElement() && |
10944 | 0 | GetContent()->AsElement()->HasAttr(kNameSpaceID_None, nsGkAtoms::layer)) { |
10945 | 0 | aList->AppendToTop( |
10946 | 0 | MakeDisplayItem<nsDisplayOwnLayer>(aBuilder, this, aList, aBuilder->CurrentActiveScrolledRoot())); |
10947 | 0 | if (aCreatedContainerItem) { |
10948 | 0 | *aCreatedContainerItem = true; |
10949 | 0 | } |
10950 | 0 | } |
10951 | 0 | } |
10952 | | |
10953 | | bool |
10954 | | nsIFrame::IsSelected() const |
10955 | 0 | { |
10956 | 0 | return (GetContent() && GetContent()->IsSelectionDescendant()) ? |
10957 | 0 | IsFrameSelected() : false; |
10958 | 0 | } |
10959 | | |
10960 | | bool |
10961 | | nsIFrame::IsStackingContext(EffectSet* aEffectSet, |
10962 | | const nsStyleDisplay* aStyleDisplay, |
10963 | | const nsStylePosition* aStylePosition, |
10964 | | const nsStyleEffects* aStyleEffects, |
10965 | | bool aIsPositioned) |
10966 | 0 | { |
10967 | 0 | return HasOpacity(aEffectSet) || |
10968 | 0 | IsTransformed(aStyleDisplay) || |
10969 | 0 | aStyleDisplay->IsContainPaint() || |
10970 | 0 | aStyleDisplay->IsContainLayout() || |
10971 | 0 | // strictly speaking, 'perspective' doesn't require visual atomicity, |
10972 | 0 | // but the spec says it acts like the rest of these |
10973 | 0 | ChildrenHavePerspective(aStyleDisplay) || |
10974 | 0 | aStyleEffects->mMixBlendMode != NS_STYLE_BLEND_NORMAL || |
10975 | 0 | nsSVGIntegrationUtils::UsingEffectsForFrame(this) || |
10976 | 0 | (aIsPositioned && (aStyleDisplay->IsPositionForcingStackingContext() || |
10977 | 0 | aStylePosition->mZIndex.GetUnit() == eStyleUnit_Integer)) || |
10978 | 0 | (aStyleDisplay->mWillChangeBitField & NS_STYLE_WILL_CHANGE_STACKING_CONTEXT) || |
10979 | 0 | aStyleDisplay->mIsolation != NS_STYLE_ISOLATION_AUTO; |
10980 | 0 | } |
10981 | | |
10982 | | bool |
10983 | | nsIFrame::IsStackingContext() |
10984 | 0 | { |
10985 | 0 | const nsStyleDisplay* disp = StyleDisplay(); |
10986 | 0 | const bool isPositioned = disp->IsAbsPosContainingBlock(this); |
10987 | 0 | return IsStackingContext(EffectSet::GetEffectSet(this), disp, |
10988 | 0 | StylePosition(), StyleEffects(), |
10989 | 0 | isPositioned); |
10990 | 0 | } |
10991 | | |
10992 | | static bool |
10993 | | IsFrameScrolledOutOfView(const nsIFrame* aTarget, |
10994 | | const nsRect& aTargetRect, |
10995 | | const nsIFrame* aParent) |
10996 | 0 | { |
10997 | 0 | nsIScrollableFrame* scrollableFrame = |
10998 | 0 | nsLayoutUtils::GetNearestScrollableFrame(const_cast<nsIFrame*>(aParent), |
10999 | 0 | nsLayoutUtils::SCROLLABLE_FIXEDPOS_FINDS_ROOT | |
11000 | 0 | nsLayoutUtils::SCROLLABLE_INCLUDE_HIDDEN); |
11001 | 0 | if (!scrollableFrame) { |
11002 | 0 | return false; |
11003 | 0 | } |
11004 | 0 | |
11005 | 0 | nsIFrame *scrollableParent = do_QueryFrame(scrollableFrame); |
11006 | 0 | nsRect scrollableRect = |
11007 | 0 | scrollableParent->GetVisualOverflowRectRelativeToSelf(); |
11008 | 0 | // We consider that the target is scrolled out if the scrollable frame is |
11009 | 0 | // empty. |
11010 | 0 | if (scrollableRect.IsEmpty()) { |
11011 | 0 | return true; |
11012 | 0 | } |
11013 | 0 | |
11014 | 0 | nsRect transformedRect = |
11015 | 0 | nsLayoutUtils::TransformFrameRectToAncestor(aTarget, |
11016 | 0 | aTargetRect, |
11017 | 0 | scrollableParent); |
11018 | 0 |
|
11019 | 0 | if (transformedRect.IsEmpty()) { |
11020 | 0 | // If the transformed rect is empty it represents a line or a point that we |
11021 | 0 | // should check is outside the the scrollable rect. |
11022 | 0 | if (transformedRect.x > scrollableRect.XMost() || |
11023 | 0 | transformedRect.y > scrollableRect.YMost() || |
11024 | 0 | scrollableRect.x > transformedRect.XMost() || |
11025 | 0 | scrollableRect.y > transformedRect.YMost()) { |
11026 | 0 | return true; |
11027 | 0 | } |
11028 | 0 | } else if (!transformedRect.Intersects(scrollableRect)) { |
11029 | 0 | return true; |
11030 | 0 | } |
11031 | 0 | |
11032 | 0 | nsIFrame* parent = scrollableParent->GetParent(); |
11033 | 0 | if (!parent) { |
11034 | 0 | return false; |
11035 | 0 | } |
11036 | 0 | |
11037 | 0 | return IsFrameScrolledOutOfView(aTarget, aTargetRect, parent); |
11038 | 0 | } |
11039 | | |
11040 | | bool |
11041 | | nsIFrame::IsScrolledOutOfView() const |
11042 | 0 | { |
11043 | 0 | nsRect rect = GetVisualOverflowRectRelativeToSelf(); |
11044 | 0 | return IsFrameScrolledOutOfView(this, rect, this); |
11045 | 0 | } |
11046 | | |
11047 | | gfx::Matrix |
11048 | | nsIFrame::ComputeWidgetTransform() |
11049 | 0 | { |
11050 | 0 | const nsStyleUIReset* uiReset = StyleUIReset(); |
11051 | 0 | if (!uiReset->mSpecifiedWindowTransform) { |
11052 | 0 | return gfx::Matrix(); |
11053 | 0 | } |
11054 | 0 | |
11055 | 0 | nsStyleTransformMatrix::TransformReferenceBox refBox; |
11056 | 0 | refBox.Init(GetSize()); |
11057 | 0 |
|
11058 | 0 | nsPresContext* presContext = PresContext(); |
11059 | 0 | int32_t appUnitsPerDevPixel = presContext->AppUnitsPerDevPixel(); |
11060 | 0 | bool dummyBool; |
11061 | 0 | gfx::Matrix4x4 matrix = |
11062 | 0 | nsStyleTransformMatrix::ReadTransforms(uiReset->mSpecifiedWindowTransform->mHead, |
11063 | 0 | refBox, |
11064 | 0 | float(appUnitsPerDevPixel), |
11065 | 0 | &dummyBool); |
11066 | 0 |
|
11067 | 0 | // Apply the -moz-window-transform-origin translation to the matrix. |
11068 | 0 | Point transformOrigin = |
11069 | 0 | nsStyleTransformMatrix::Convert2DPosition(uiReset->mWindowTransformOrigin, |
11070 | 0 | refBox, appUnitsPerDevPixel); |
11071 | 0 | matrix.ChangeBasis(Point3D(transformOrigin.x, transformOrigin.y, 0)); |
11072 | 0 |
|
11073 | 0 | gfx::Matrix result2d; |
11074 | 0 | if (!matrix.CanDraw2D(&result2d)) { |
11075 | 0 | // FIXME: It would be preferable to reject non-2D transforms at parse time. |
11076 | 0 | NS_WARNING("-moz-window-transform does not describe a 2D transform, " |
11077 | 0 | "but only 2d transforms are supported"); |
11078 | 0 | return gfx::Matrix(); |
11079 | 0 | } |
11080 | 0 |
|
11081 | 0 | return result2d; |
11082 | 0 | } |
11083 | | |
11084 | | static already_AddRefed<nsIWidget> |
11085 | | GetWindowWidget(nsPresContext* aPresContext) |
11086 | 0 | { |
11087 | 0 | // We want to obtain the widget for the window. We can't use any of these |
11088 | 0 | // methods: nsPresContext::GetRootWidget, nsPresContext::GetNearestWidget, |
11089 | 0 | // nsIFrame::GetNearestWidget because those deal with child widgets and |
11090 | 0 | // there is no parent widget connection between child widgets and the |
11091 | 0 | // window widget that contains them. |
11092 | 0 | nsCOMPtr<nsISupports> container = aPresContext->Document()->GetContainer(); |
11093 | 0 | nsCOMPtr<nsIBaseWindow> baseWindow = do_QueryInterface(container); |
11094 | 0 | if (!baseWindow) { |
11095 | 0 | return nullptr; |
11096 | 0 | } |
11097 | 0 | |
11098 | 0 | nsCOMPtr<nsIWidget> mainWidget; |
11099 | 0 | baseWindow->GetMainWidget(getter_AddRefs(mainWidget)); |
11100 | 0 | return mainWidget.forget(); |
11101 | 0 | } |
11102 | | |
11103 | | void |
11104 | | nsIFrame::UpdateWidgetProperties() |
11105 | 0 | { |
11106 | 0 | nsPresContext* presContext = PresContext(); |
11107 | 0 | if (presContext->IsRoot() || !presContext->IsChrome()) { |
11108 | 0 | // Don't do anything for documents that aren't the root chrome document. |
11109 | 0 | return; |
11110 | 0 | } |
11111 | 0 | nsIFrame* rootFrame = |
11112 | 0 | presContext->FrameConstructor()->GetRootElementStyleFrame(); |
11113 | 0 | if (this != rootFrame) { |
11114 | 0 | // Only the window's root style frame is relevant for widget properties. |
11115 | 0 | return; |
11116 | 0 | } |
11117 | 0 | if (nsCOMPtr<nsIWidget> widget = GetWindowWidget(presContext)) { |
11118 | 0 | widget->SetWindowOpacity(StyleUIReset()->mWindowOpacity); |
11119 | 0 | widget->SetWindowTransform(ComputeWidgetTransform()); |
11120 | 0 | } |
11121 | 0 | } |
11122 | | |
11123 | | void |
11124 | | nsIFrame::DoUpdateStyleOfOwnedAnonBoxes(ServoRestyleState& aRestyleState) |
11125 | 0 | { |
11126 | 0 | // As a special case, we check for {ib}-split block frames here, rather |
11127 | 0 | // than have an nsInlineFrame::AppendDirectlyOwnedAnonBoxes implementation |
11128 | 0 | // that returns them. |
11129 | 0 | // |
11130 | 0 | // (If we did handle them in AppendDirectlyOwnedAnonBoxes, we would have to |
11131 | 0 | // return *all* of the in-flow {ib}-split block frames, not just the first |
11132 | 0 | // one. For restyling, we really just need the first in flow, and the other |
11133 | 0 | // user of the AppendOwnedAnonBoxes API, AllChildIterator, doesn't need to |
11134 | 0 | // know about them at all, since these block frames never create NAC. So we |
11135 | 0 | // avoid any unncessary hashtable lookups for the {ib}-split frames by calling |
11136 | 0 | // UpdateStyleOfOwnedAnonBoxesForIBSplit directly here.) |
11137 | 0 | if (IsInlineFrame()) { |
11138 | 0 | if ((GetStateBits() & NS_FRAME_PART_OF_IBSPLIT)) { |
11139 | 0 | static_cast<nsInlineFrame*>(this)->UpdateStyleOfOwnedAnonBoxesForIBSplit( |
11140 | 0 | aRestyleState); |
11141 | 0 | } |
11142 | 0 | return; |
11143 | 0 | } |
11144 | 0 |
|
11145 | 0 | AutoTArray<OwnedAnonBox,4> frames; |
11146 | 0 | AppendDirectlyOwnedAnonBoxes(frames); |
11147 | 0 | for (OwnedAnonBox& box : frames) { |
11148 | 0 | if (box.mUpdateStyleFn) { |
11149 | 0 | box.mUpdateStyleFn(this, box.mAnonBoxFrame, aRestyleState); |
11150 | 0 | } else { |
11151 | 0 | UpdateStyleOfChildAnonBox(box.mAnonBoxFrame, aRestyleState); |
11152 | 0 | } |
11153 | 0 | } |
11154 | 0 | } |
11155 | | |
11156 | | /* virtual */ void |
11157 | | nsIFrame::AppendDirectlyOwnedAnonBoxes(nsTArray<OwnedAnonBox>& aResult) |
11158 | 0 | { |
11159 | 0 | MOZ_ASSERT(!(GetStateBits() & NS_FRAME_OWNS_ANON_BOXES)); |
11160 | 0 | MOZ_ASSERT(false, "Why did this get called?"); |
11161 | 0 | } |
11162 | | |
11163 | | void |
11164 | | nsIFrame::DoAppendOwnedAnonBoxes(nsTArray<OwnedAnonBox>& aResult) |
11165 | 0 | { |
11166 | 0 | size_t i = aResult.Length(); |
11167 | 0 | AppendDirectlyOwnedAnonBoxes(aResult); |
11168 | 0 |
|
11169 | 0 | // After appending the directly owned anonymous boxes of this frame to |
11170 | 0 | // aResult above, we need to check each of them to see if they own |
11171 | 0 | // any anonymous boxes themselves. Note that we keep progressing |
11172 | 0 | // through aResult, looking for additional entries in aResult from these |
11173 | 0 | // subsequent AppendDirectlyOwnedAnonBoxes calls. (Thus we can't |
11174 | 0 | // use a ranged for loop here.) |
11175 | 0 |
|
11176 | 0 | while (i < aResult.Length()) { |
11177 | 0 | nsIFrame* f = aResult[i].mAnonBoxFrame; |
11178 | 0 | if (f->GetStateBits() & NS_FRAME_OWNS_ANON_BOXES) { |
11179 | 0 | f->AppendDirectlyOwnedAnonBoxes(aResult); |
11180 | 0 | } |
11181 | 0 | ++i; |
11182 | 0 | } |
11183 | 0 | } |
11184 | | |
11185 | | nsIFrame::CaretPosition::CaretPosition() |
11186 | | : mContentOffset(0) |
11187 | 0 | { |
11188 | 0 | } |
11189 | | |
11190 | | nsIFrame::CaretPosition::~CaretPosition() |
11191 | 0 | { |
11192 | 0 | } |
11193 | | |
11194 | | bool |
11195 | | nsFrame::HasCSSAnimations() |
11196 | 0 | { |
11197 | 0 | auto collection = |
11198 | 0 | AnimationCollection<CSSAnimation>::GetAnimationCollection(this); |
11199 | 0 | return collection && collection->mAnimations.Length() > 0; |
11200 | 0 | } |
11201 | | |
11202 | | bool |
11203 | | nsFrame::HasCSSTransitions() |
11204 | 0 | { |
11205 | 0 | auto collection = |
11206 | 0 | AnimationCollection<CSSTransition>::GetAnimationCollection(this); |
11207 | 0 | return collection && collection->mAnimations.Length() > 0; |
11208 | 0 | } |
11209 | | |
11210 | | void |
11211 | | nsIFrame::AddSizeOfExcludingThisForTree(nsWindowSizes& aSizes) const |
11212 | 0 | { |
11213 | 0 | aSizes.mLayoutFramePropertiesSize += |
11214 | 0 | mProperties.SizeOfExcludingThis(aSizes.mState.mMallocSizeOf); |
11215 | 0 |
|
11216 | 0 | // We don't do this for Gecko because this stuff is stored in the nsPresArena |
11217 | 0 | // and so measured elsewhere. |
11218 | 0 | if (!aSizes.mState.HaveSeenPtr(mComputedStyle)) { |
11219 | 0 | mComputedStyle->AddSizeOfIncludingThis( |
11220 | 0 | aSizes, &aSizes.mLayoutComputedValuesNonDom); |
11221 | 0 | } |
11222 | 0 |
|
11223 | 0 | // And our additional styles. |
11224 | 0 | int32_t index = 0; |
11225 | 0 | while (auto* extra = GetAdditionalComputedStyle(index++)) { |
11226 | 0 | if (!aSizes.mState.HaveSeenPtr(extra)) { |
11227 | 0 | extra->AddSizeOfIncludingThis( |
11228 | 0 | aSizes, &aSizes.mLayoutComputedValuesNonDom); |
11229 | 0 | } |
11230 | 0 | } |
11231 | 0 |
|
11232 | 0 | FrameChildListIterator iter(this); |
11233 | 0 | while (!iter.IsDone()) { |
11234 | 0 | for (const nsIFrame* f : iter.CurrentList()) { |
11235 | 0 | f->AddSizeOfExcludingThisForTree(aSizes); |
11236 | 0 | } |
11237 | 0 | iter.Next(); |
11238 | 0 | } |
11239 | 0 | } |
11240 | | |
11241 | | CompositorHitTestInfo |
11242 | | nsIFrame::GetCompositorHitTestInfo(nsDisplayListBuilder* aBuilder) |
11243 | 0 | { |
11244 | 0 | CompositorHitTestInfo result = CompositorHitTestInfo::eInvisibleToHitTest; |
11245 | 0 |
|
11246 | 0 | if (aBuilder->IsInsidePointerEventsNoneDoc()) { |
11247 | 0 | // Somewhere up the parent document chain is a subdocument with pointer- |
11248 | 0 | // events:none set on it. |
11249 | 0 | return result; |
11250 | 0 | } |
11251 | 0 | if (!GetParent()) { |
11252 | 0 | MOZ_ASSERT(IsViewportFrame()); |
11253 | 0 | // Viewport frames are never event targets, other frames, like canvas frames, |
11254 | 0 | // are the event targets for any regions viewport frames may cover. |
11255 | 0 | return result; |
11256 | 0 | } |
11257 | 0 | const uint8_t pointerEvents = StyleUI()->GetEffectivePointerEvents(this); |
11258 | 0 | if (pointerEvents == NS_STYLE_POINTER_EVENTS_NONE) { |
11259 | 0 | return result; |
11260 | 0 | } |
11261 | 0 | if (!StyleVisibility()->IsVisible()) { |
11262 | 0 | return result; |
11263 | 0 | } |
11264 | 0 | |
11265 | 0 | // Anything that didn't match the above conditions is visible to hit-testing. |
11266 | 0 | result |= CompositorHitTestInfo::eVisibleToHitTest; |
11267 | 0 |
|
11268 | 0 | if (aBuilder->IsBuildingNonLayerizedScrollbar() || |
11269 | 0 | aBuilder->GetAncestorHasApzAwareEventHandler()) { |
11270 | 0 | // Scrollbars may be painted into a layer below the actual layer they will |
11271 | 0 | // scroll, and therefore wheel events may be dispatched to the outer frame |
11272 | 0 | // instead of the intended scrollframe. To address this, we force a d-t-c |
11273 | 0 | // region on scrollbar frames that won't be placed in their own layer. See |
11274 | 0 | // bug 1213324 for details. |
11275 | 0 | result |= CompositorHitTestInfo::eDispatchToContent; |
11276 | 0 | } else if (IsObjectFrame()) { |
11277 | 0 | // If the frame is a plugin frame and wants to handle wheel events as |
11278 | 0 | // default action, we should add the frame to dispatch-to-content region. |
11279 | 0 | nsPluginFrame* pluginFrame = do_QueryFrame(this); |
11280 | 0 | if (pluginFrame && pluginFrame->WantsToHandleWheelEventAsDefaultAction()) { |
11281 | 0 | result |= CompositorHitTestInfo::eDispatchToContent; |
11282 | 0 | } |
11283 | 0 | } |
11284 | 0 |
|
11285 | 0 | nsIDocShell* docShell = nullptr; |
11286 | 0 | if (PresShell()->GetDocument()) { |
11287 | 0 | docShell = PresShell()->GetDocument()->GetDocShell(); |
11288 | 0 | } |
11289 | 0 | if (dom::TouchEvent::PrefEnabled(docShell)) { |
11290 | 0 | // Inherit the touch-action flags from the parent, if there is one. We do this |
11291 | 0 | // because of how the touch-action on a frame combines the touch-action from |
11292 | 0 | // ancestor DOM elements. Refer to the documentation in TouchActionHelper.cpp |
11293 | 0 | // for details; this code is meant to be equivalent to that code, but woven |
11294 | 0 | // into the top-down recursive display list building process. |
11295 | 0 | CompositorHitTestInfo inheritedTouchAction = CompositorHitTestInfo::eInvisibleToHitTest; |
11296 | 0 | if (nsDisplayCompositorHitTestInfo* parentInfo = aBuilder->GetCompositorHitTestInfo()) { |
11297 | 0 | inheritedTouchAction = (parentInfo->HitTestInfo() & CompositorHitTestInfo::eTouchActionMask); |
11298 | 0 | } |
11299 | 0 |
|
11300 | 0 | nsIFrame* touchActionFrame = this; |
11301 | 0 | if (nsIScrollableFrame* scrollFrame = nsLayoutUtils::GetScrollableFrameFor(this)) { |
11302 | 0 | touchActionFrame = do_QueryFrame(scrollFrame); |
11303 | 0 | // On scrollframes, stop inheriting the pan-x and pan-y flags; instead, |
11304 | 0 | // reset them back to zero to allow panning on the scrollframe unless we |
11305 | 0 | // encounter an element that disables it that's inside the scrollframe. |
11306 | 0 | // This is equivalent to the |considerPanning| variable in |
11307 | 0 | // TouchActionHelper.cpp, but for a top-down traversal. |
11308 | 0 | CompositorHitTestInfo panMask = CompositorHitTestInfo::eTouchActionPanXDisabled |
11309 | 0 | | CompositorHitTestInfo::eTouchActionPanYDisabled; |
11310 | 0 | inheritedTouchAction &= ~panMask; |
11311 | 0 | } |
11312 | 0 |
|
11313 | 0 | result |= inheritedTouchAction; |
11314 | 0 |
|
11315 | 0 | const uint32_t touchAction = nsLayoutUtils::GetTouchActionFromFrame(touchActionFrame); |
11316 | 0 | // The CSS allows the syntax auto | none | [pan-x || pan-y] | manipulation |
11317 | 0 | // so we can eliminate some combinations of things. |
11318 | 0 | if (touchAction == NS_STYLE_TOUCH_ACTION_AUTO) { |
11319 | 0 | // nothing to do |
11320 | 0 | } else if (touchAction & NS_STYLE_TOUCH_ACTION_MANIPULATION) { |
11321 | 0 | result |= CompositorHitTestInfo::eTouchActionDoubleTapZoomDisabled; |
11322 | 0 | } else { |
11323 | 0 | // This path handles the cases none | [pan-x || pan-y] and so both |
11324 | 0 | // double-tap and pinch zoom are disabled in here. |
11325 | 0 | result |= CompositorHitTestInfo::eTouchActionPinchZoomDisabled |
11326 | 0 | | CompositorHitTestInfo::eTouchActionDoubleTapZoomDisabled; |
11327 | 0 |
|
11328 | 0 | if (!(touchAction & NS_STYLE_TOUCH_ACTION_PAN_X)) { |
11329 | 0 | result |= CompositorHitTestInfo::eTouchActionPanXDisabled; |
11330 | 0 | } |
11331 | 0 | if (!(touchAction & NS_STYLE_TOUCH_ACTION_PAN_Y)) { |
11332 | 0 | result |= CompositorHitTestInfo::eTouchActionPanYDisabled; |
11333 | 0 | } |
11334 | 0 | if (touchAction & NS_STYLE_TOUCH_ACTION_NONE) { |
11335 | 0 | // all the touch-action disabling flags will already have been set above |
11336 | 0 | MOZ_ASSERT((result & CompositorHitTestInfo::eTouchActionMask) |
11337 | 0 | == CompositorHitTestInfo::eTouchActionMask); |
11338 | 0 | } |
11339 | 0 | } |
11340 | 0 | } |
11341 | 0 |
|
11342 | 0 | const Maybe<ScrollDirection> scrollDirection = aBuilder->GetCurrentScrollbarDirection(); |
11343 | 0 | if (scrollDirection.isSome()) { |
11344 | 0 | if (GetContent()->IsXULElement(nsGkAtoms::thumb)) { |
11345 | 0 | const bool thumbGetsLayer = aBuilder->GetCurrentScrollbarTarget() != |
11346 | 0 | layers::FrameMetrics::NULL_SCROLL_ID; |
11347 | 0 | if (thumbGetsLayer) { |
11348 | 0 | result |= CompositorHitTestInfo::eScrollbarThumb; |
11349 | 0 | } else { |
11350 | 0 | result |= CompositorHitTestInfo::eDispatchToContent; |
11351 | 0 | } |
11352 | 0 | } |
11353 | 0 |
|
11354 | 0 | if (*scrollDirection == ScrollDirection::eVertical) { |
11355 | 0 | result |= CompositorHitTestInfo::eScrollbarVertical; |
11356 | 0 | } |
11357 | 0 |
|
11358 | 0 | // includes the ScrollbarFrame, SliderFrame, anything else that |
11359 | 0 | // might be inside the xul:scrollbar |
11360 | 0 | result |= CompositorHitTestInfo::eScrollbar; |
11361 | 0 | } |
11362 | 0 |
|
11363 | 0 | return result; |
11364 | 0 | } |
11365 | | |
11366 | | // Returns true if we can guarantee there is no visible descendants. |
11367 | | static bool |
11368 | | HasNoVisibleDescendants(const nsIFrame* aFrame) |
11369 | 0 | { |
11370 | 0 | for (nsIFrame::ChildListIterator lists(aFrame); |
11371 | 0 | !lists.IsDone(); |
11372 | 0 | lists.Next()) { |
11373 | 0 | for (nsIFrame* f : lists.CurrentList()) { |
11374 | 0 | if (nsPlaceholderFrame::GetRealFrameFor(f)-> |
11375 | 0 | IsVisibleOrMayHaveVisibleDescendants()) { |
11376 | 0 | return false; |
11377 | 0 | } |
11378 | 0 | } |
11379 | 0 | } |
11380 | 0 | return true; |
11381 | 0 | } |
11382 | | |
11383 | | void |
11384 | | nsIFrame::UpdateVisibleDescendantsState() |
11385 | 0 | { |
11386 | 0 | if (StyleVisibility()->IsVisible()) { |
11387 | 0 | // Notify invisible ancestors that a visible descendant exists now. |
11388 | 0 | nsIFrame* ancestor; |
11389 | 0 | for (ancestor = GetInFlowParent(); |
11390 | 0 | ancestor && !ancestor->StyleVisibility()->IsVisible(); |
11391 | 0 | ancestor = ancestor->GetInFlowParent()) { |
11392 | 0 | ancestor->mAllDescendantsAreInvisible = false; |
11393 | 0 | } |
11394 | 0 | } else { |
11395 | 0 | mAllDescendantsAreInvisible = HasNoVisibleDescendants(this); |
11396 | 0 | } |
11397 | 0 | } |
11398 | | |
11399 | | // Box layout debugging |
11400 | | #ifdef DEBUG_REFLOW |
11401 | | int32_t gIndent2 = 0; |
11402 | | |
11403 | | void |
11404 | | nsAdaptorAddIndents() |
11405 | | { |
11406 | | for(int32_t i=0; i < gIndent2; i++) |
11407 | | { |
11408 | | printf(" "); |
11409 | | } |
11410 | | } |
11411 | | |
11412 | | void |
11413 | | nsAdaptorPrintReason(ReflowInput& aReflowInput) |
11414 | | { |
11415 | | char* reflowReasonString; |
11416 | | |
11417 | | switch(aReflowInput.reason) |
11418 | | { |
11419 | | case eReflowReason_Initial: |
11420 | | reflowReasonString = "initial"; |
11421 | | break; |
11422 | | |
11423 | | case eReflowReason_Resize: |
11424 | | reflowReasonString = "resize"; |
11425 | | break; |
11426 | | case eReflowReason_Dirty: |
11427 | | reflowReasonString = "dirty"; |
11428 | | break; |
11429 | | case eReflowReason_StyleChange: |
11430 | | reflowReasonString = "stylechange"; |
11431 | | break; |
11432 | | case eReflowReason_Incremental: |
11433 | | { |
11434 | | switch (aReflowInput.reflowCommand->Type()) { |
11435 | | case eReflowType_StyleChanged: |
11436 | | reflowReasonString = "incremental (StyleChanged)"; |
11437 | | break; |
11438 | | case eReflowType_ReflowDirty: |
11439 | | reflowReasonString = "incremental (ReflowDirty)"; |
11440 | | break; |
11441 | | default: |
11442 | | reflowReasonString = "incremental (Unknown)"; |
11443 | | } |
11444 | | } |
11445 | | break; |
11446 | | default: |
11447 | | reflowReasonString = "unknown"; |
11448 | | break; |
11449 | | } |
11450 | | |
11451 | | printf("%s",reflowReasonString); |
11452 | | } |
11453 | | |
11454 | | #endif |
11455 | | |
11456 | | #ifdef DEBUG |
11457 | | static void |
11458 | | GetTagName(nsFrame* aFrame, nsIContent* aContent, int aResultSize, |
11459 | | char* aResult) |
11460 | | { |
11461 | | if (aContent) { |
11462 | | snprintf(aResult, aResultSize, "%s@%p", |
11463 | | nsAtomCString(aContent->NodeInfo()->NameAtom()).get(), aFrame); |
11464 | | } |
11465 | | else { |
11466 | | snprintf(aResult, aResultSize, "@%p", aFrame); |
11467 | | } |
11468 | | } |
11469 | | |
11470 | | void |
11471 | | nsFrame::Trace(const char* aMethod, bool aEnter) |
11472 | | { |
11473 | | if (NS_FRAME_LOG_TEST(sFrameLogModule, NS_FRAME_TRACE_CALLS)) { |
11474 | | char tagbuf[40]; |
11475 | | GetTagName(this, mContent, sizeof(tagbuf), tagbuf); |
11476 | | printf_stderr("%s: %s %s", tagbuf, aEnter ? "enter" : "exit", aMethod); |
11477 | | } |
11478 | | } |
11479 | | |
11480 | | void |
11481 | | nsFrame::Trace(const char* aMethod, bool aEnter, const nsReflowStatus& aStatus) |
11482 | | { |
11483 | | if (NS_FRAME_LOG_TEST(sFrameLogModule, NS_FRAME_TRACE_CALLS)) { |
11484 | | char tagbuf[40]; |
11485 | | GetTagName(this, mContent, sizeof(tagbuf), tagbuf); |
11486 | | printf_stderr("%s: %s %s, status=%scomplete%s", |
11487 | | tagbuf, aEnter ? "enter" : "exit", aMethod, |
11488 | | aStatus.IsIncomplete() ? "not" : "", |
11489 | | (aStatus.NextInFlowNeedsReflow()) ? "+reflow" : ""); |
11490 | | } |
11491 | | } |
11492 | | |
11493 | | void |
11494 | | nsFrame::TraceMsg(const char* aFormatString, ...) |
11495 | | { |
11496 | | if (NS_FRAME_LOG_TEST(sFrameLogModule, NS_FRAME_TRACE_CALLS)) { |
11497 | | // Format arguments into a buffer |
11498 | | char argbuf[200]; |
11499 | | va_list ap; |
11500 | | va_start(ap, aFormatString); |
11501 | | VsprintfLiteral(argbuf, aFormatString, ap); |
11502 | | va_end(ap); |
11503 | | |
11504 | | char tagbuf[40]; |
11505 | | GetTagName(this, mContent, sizeof(tagbuf), tagbuf); |
11506 | | printf_stderr("%s: %s", tagbuf, argbuf); |
11507 | | } |
11508 | | } |
11509 | | |
11510 | | void |
11511 | | nsFrame::VerifyDirtyBitSet(const nsFrameList& aFrameList) |
11512 | | { |
11513 | | for (nsFrameList::Enumerator e(aFrameList); !e.AtEnd(); e.Next()) { |
11514 | | NS_ASSERTION(e.get()->GetStateBits() & NS_FRAME_IS_DIRTY, |
11515 | | "dirty bit not set"); |
11516 | | } |
11517 | | } |
11518 | | |
11519 | | // Start Display Reflow |
11520 | | #ifdef DEBUG |
11521 | | |
11522 | | DR_cookie::DR_cookie(nsPresContext* aPresContext, |
11523 | | nsIFrame* aFrame, |
11524 | | const ReflowInput& aReflowInput, |
11525 | | ReflowOutput& aMetrics, |
11526 | | nsReflowStatus& aStatus) |
11527 | | :mPresContext(aPresContext), mFrame(aFrame), mReflowInput(aReflowInput), mMetrics(aMetrics), mStatus(aStatus) |
11528 | | { |
11529 | | MOZ_COUNT_CTOR(DR_cookie); |
11530 | | mValue = nsFrame::DisplayReflowEnter(aPresContext, mFrame, mReflowInput); |
11531 | | } |
11532 | | |
11533 | | DR_cookie::~DR_cookie() |
11534 | | { |
11535 | | MOZ_COUNT_DTOR(DR_cookie); |
11536 | | nsFrame::DisplayReflowExit(mPresContext, mFrame, mMetrics, mStatus, mValue); |
11537 | | } |
11538 | | |
11539 | | DR_layout_cookie::DR_layout_cookie(nsIFrame* aFrame) |
11540 | | : mFrame(aFrame) |
11541 | | { |
11542 | | MOZ_COUNT_CTOR(DR_layout_cookie); |
11543 | | mValue = nsFrame::DisplayLayoutEnter(mFrame); |
11544 | | } |
11545 | | |
11546 | | DR_layout_cookie::~DR_layout_cookie() |
11547 | | { |
11548 | | MOZ_COUNT_DTOR(DR_layout_cookie); |
11549 | | nsFrame::DisplayLayoutExit(mFrame, mValue); |
11550 | | } |
11551 | | |
11552 | | DR_intrinsic_inline_size_cookie::DR_intrinsic_inline_size_cookie( |
11553 | | nsIFrame* aFrame, |
11554 | | const char* aType, |
11555 | | nscoord& aResult) |
11556 | | : mFrame(aFrame) |
11557 | | , mType(aType) |
11558 | | , mResult(aResult) |
11559 | | { |
11560 | | MOZ_COUNT_CTOR(DR_intrinsic_inline_size_cookie); |
11561 | | mValue = nsFrame::DisplayIntrinsicISizeEnter(mFrame, mType); |
11562 | | } |
11563 | | |
11564 | | DR_intrinsic_inline_size_cookie::~DR_intrinsic_inline_size_cookie() |
11565 | | { |
11566 | | MOZ_COUNT_DTOR(DR_intrinsic_inline_size_cookie); |
11567 | | nsFrame::DisplayIntrinsicISizeExit(mFrame, mType, mResult, mValue); |
11568 | | } |
11569 | | |
11570 | | DR_intrinsic_size_cookie::DR_intrinsic_size_cookie( |
11571 | | nsIFrame* aFrame, |
11572 | | const char* aType, |
11573 | | nsSize& aResult) |
11574 | | : mFrame(aFrame) |
11575 | | , mType(aType) |
11576 | | , mResult(aResult) |
11577 | | { |
11578 | | MOZ_COUNT_CTOR(DR_intrinsic_size_cookie); |
11579 | | mValue = nsFrame::DisplayIntrinsicSizeEnter(mFrame, mType); |
11580 | | } |
11581 | | |
11582 | | DR_intrinsic_size_cookie::~DR_intrinsic_size_cookie() |
11583 | | { |
11584 | | MOZ_COUNT_DTOR(DR_intrinsic_size_cookie); |
11585 | | nsFrame::DisplayIntrinsicSizeExit(mFrame, mType, mResult, mValue); |
11586 | | } |
11587 | | |
11588 | | DR_init_constraints_cookie::DR_init_constraints_cookie( |
11589 | | nsIFrame* aFrame, |
11590 | | ReflowInput* aState, |
11591 | | nscoord aCBWidth, |
11592 | | nscoord aCBHeight, |
11593 | | const nsMargin* aMargin, |
11594 | | const nsMargin* aPadding) |
11595 | | : mFrame(aFrame) |
11596 | | , mState(aState) |
11597 | | { |
11598 | | MOZ_COUNT_CTOR(DR_init_constraints_cookie); |
11599 | | mValue = ReflowInput::DisplayInitConstraintsEnter(mFrame, mState, |
11600 | | aCBWidth, aCBHeight, |
11601 | | aMargin, aPadding); |
11602 | | } |
11603 | | |
11604 | | DR_init_constraints_cookie::~DR_init_constraints_cookie() |
11605 | | { |
11606 | | MOZ_COUNT_DTOR(DR_init_constraints_cookie); |
11607 | | ReflowInput::DisplayInitConstraintsExit(mFrame, mState, mValue); |
11608 | | } |
11609 | | |
11610 | | DR_init_offsets_cookie::DR_init_offsets_cookie( |
11611 | | nsIFrame* aFrame, |
11612 | | SizeComputationInput* aState, |
11613 | | nscoord aPercentBasis, |
11614 | | WritingMode aCBWritingMode, |
11615 | | const nsMargin* aMargin, |
11616 | | const nsMargin* aPadding) |
11617 | | : mFrame(aFrame) |
11618 | | , mState(aState) |
11619 | | { |
11620 | | MOZ_COUNT_CTOR(DR_init_offsets_cookie); |
11621 | | mValue = SizeComputationInput::DisplayInitOffsetsEnter(mFrame, mState, |
11622 | | aPercentBasis, |
11623 | | aCBWritingMode, |
11624 | | aMargin, aPadding); |
11625 | | } |
11626 | | |
11627 | | DR_init_offsets_cookie::~DR_init_offsets_cookie() |
11628 | | { |
11629 | | MOZ_COUNT_DTOR(DR_init_offsets_cookie); |
11630 | | SizeComputationInput::DisplayInitOffsetsExit(mFrame, mState, mValue); |
11631 | | } |
11632 | | |
11633 | | DR_init_type_cookie::DR_init_type_cookie( |
11634 | | nsIFrame* aFrame, |
11635 | | ReflowInput* aState) |
11636 | | : mFrame(aFrame) |
11637 | | , mState(aState) |
11638 | | { |
11639 | | MOZ_COUNT_CTOR(DR_init_type_cookie); |
11640 | | mValue = ReflowInput::DisplayInitFrameTypeEnter(mFrame, mState); |
11641 | | } |
11642 | | |
11643 | | DR_init_type_cookie::~DR_init_type_cookie() |
11644 | | { |
11645 | | MOZ_COUNT_DTOR(DR_init_type_cookie); |
11646 | | ReflowInput::DisplayInitFrameTypeExit(mFrame, mState, mValue); |
11647 | | } |
11648 | | |
11649 | | struct DR_FrameTypeInfo; |
11650 | | struct DR_FrameTreeNode; |
11651 | | struct DR_Rule; |
11652 | | |
11653 | | struct DR_State |
11654 | | { |
11655 | | DR_State(); |
11656 | | ~DR_State(); |
11657 | | void Init(); |
11658 | | void AddFrameTypeInfo(LayoutFrameType aFrameType, |
11659 | | const char* aFrameNameAbbrev, |
11660 | | const char* aFrameName); |
11661 | | DR_FrameTypeInfo* GetFrameTypeInfo(LayoutFrameType aFrameType); |
11662 | | DR_FrameTypeInfo* GetFrameTypeInfo(char* aFrameName); |
11663 | | void InitFrameTypeTable(); |
11664 | | DR_FrameTreeNode* CreateTreeNode(nsIFrame* aFrame, |
11665 | | const ReflowInput* aReflowInput); |
11666 | | void FindMatchingRule(DR_FrameTreeNode& aNode); |
11667 | | bool RuleMatches(DR_Rule& aRule, |
11668 | | DR_FrameTreeNode& aNode); |
11669 | | bool GetToken(FILE* aFile, |
11670 | | char* aBuf, |
11671 | | size_t aBufSize); |
11672 | | DR_Rule* ParseRule(FILE* aFile); |
11673 | | void ParseRulesFile(); |
11674 | | void AddRule(nsTArray<DR_Rule*>& aRules, |
11675 | | DR_Rule& aRule); |
11676 | | bool IsWhiteSpace(int c); |
11677 | | bool GetNumber(char* aBuf, |
11678 | | int32_t& aNumber); |
11679 | | void PrettyUC(nscoord aSize, |
11680 | | char* aBuf, |
11681 | | int aBufSize); |
11682 | | void PrintMargin(const char* tag, const nsMargin* aMargin); |
11683 | | void DisplayFrameTypeInfo(nsIFrame* aFrame, |
11684 | | int32_t aIndent); |
11685 | | void DeleteTreeNode(DR_FrameTreeNode& aNode); |
11686 | | |
11687 | | bool mInited; |
11688 | | bool mActive; |
11689 | | int32_t mCount; |
11690 | | int32_t mAssert; |
11691 | | int32_t mIndent; |
11692 | | bool mIndentUndisplayedFrames; |
11693 | | bool mDisplayPixelErrors; |
11694 | | nsTArray<DR_Rule*> mWildRules; |
11695 | | nsTArray<DR_FrameTypeInfo> mFrameTypeTable; |
11696 | | // reflow specific state |
11697 | | nsTArray<DR_FrameTreeNode*> mFrameTreeLeaves; |
11698 | | }; |
11699 | | |
11700 | | static DR_State *DR_state; // the one and only DR_State |
11701 | | |
11702 | | struct DR_RulePart |
11703 | | { |
11704 | | explicit DR_RulePart(LayoutFrameType aFrameType) |
11705 | | : mFrameType(aFrameType) |
11706 | | , mNext(0) |
11707 | | {} |
11708 | | |
11709 | | void Destroy(); |
11710 | | |
11711 | | LayoutFrameType mFrameType; |
11712 | | DR_RulePart* mNext; |
11713 | | }; |
11714 | | |
11715 | | void DR_RulePart::Destroy() |
11716 | | { |
11717 | | if (mNext) { |
11718 | | mNext->Destroy(); |
11719 | | } |
11720 | | delete this; |
11721 | | } |
11722 | | |
11723 | | struct DR_Rule |
11724 | | { |
11725 | | DR_Rule() : mLength(0), mTarget(nullptr), mDisplay(false) { |
11726 | | MOZ_COUNT_CTOR(DR_Rule); |
11727 | | } |
11728 | | ~DR_Rule() { |
11729 | | if (mTarget) mTarget->Destroy(); |
11730 | | MOZ_COUNT_DTOR(DR_Rule); |
11731 | | } |
11732 | | void AddPart(LayoutFrameType aFrameType); |
11733 | | |
11734 | | uint32_t mLength; |
11735 | | DR_RulePart* mTarget; |
11736 | | bool mDisplay; |
11737 | | }; |
11738 | | |
11739 | | void |
11740 | | DR_Rule::AddPart(LayoutFrameType aFrameType) |
11741 | | { |
11742 | | DR_RulePart* newPart = new DR_RulePart(aFrameType); |
11743 | | newPart->mNext = mTarget; |
11744 | | mTarget = newPart; |
11745 | | mLength++; |
11746 | | } |
11747 | | |
11748 | | struct DR_FrameTypeInfo |
11749 | | { |
11750 | | DR_FrameTypeInfo(LayoutFrameType aFrameType, |
11751 | | const char* aFrameNameAbbrev, |
11752 | | const char* aFrameName); |
11753 | | ~DR_FrameTypeInfo() { |
11754 | | int32_t numElements; |
11755 | | numElements = mRules.Length(); |
11756 | | for (int32_t i = numElements - 1; i >= 0; i--) { |
11757 | | delete mRules.ElementAt(i); |
11758 | | } |
11759 | | } |
11760 | | |
11761 | | LayoutFrameType mType; |
11762 | | char mNameAbbrev[16]; |
11763 | | char mName[32]; |
11764 | | nsTArray<DR_Rule*> mRules; |
11765 | | private: |
11766 | | DR_FrameTypeInfo& operator=(const DR_FrameTypeInfo&) = delete; |
11767 | | }; |
11768 | | |
11769 | | DR_FrameTypeInfo::DR_FrameTypeInfo(LayoutFrameType aFrameType, |
11770 | | const char* aFrameNameAbbrev, |
11771 | | const char* aFrameName) |
11772 | | { |
11773 | | mType = aFrameType; |
11774 | | PL_strncpyz(mNameAbbrev, aFrameNameAbbrev, sizeof(mNameAbbrev)); |
11775 | | PL_strncpyz(mName, aFrameName, sizeof(mName)); |
11776 | | } |
11777 | | |
11778 | | struct DR_FrameTreeNode |
11779 | | { |
11780 | | DR_FrameTreeNode(nsIFrame* aFrame, DR_FrameTreeNode* aParent) : mFrame(aFrame), mParent(aParent), mDisplay(0), mIndent(0) |
11781 | | { |
11782 | | MOZ_COUNT_CTOR(DR_FrameTreeNode); |
11783 | | } |
11784 | | |
11785 | | ~DR_FrameTreeNode() |
11786 | | { |
11787 | | MOZ_COUNT_DTOR(DR_FrameTreeNode); |
11788 | | } |
11789 | | |
11790 | | nsIFrame* mFrame; |
11791 | | DR_FrameTreeNode* mParent; |
11792 | | bool mDisplay; |
11793 | | uint32_t mIndent; |
11794 | | }; |
11795 | | |
11796 | | // DR_State implementation |
11797 | | |
11798 | | DR_State::DR_State() |
11799 | | : mInited(false), mActive(false), mCount(0), mAssert(-1), mIndent(0), |
11800 | | mIndentUndisplayedFrames(false), mDisplayPixelErrors(false) |
11801 | | { |
11802 | | MOZ_COUNT_CTOR(DR_State); |
11803 | | } |
11804 | | |
11805 | | void DR_State::Init() |
11806 | | { |
11807 | | char* env = PR_GetEnv("GECKO_DISPLAY_REFLOW_ASSERT"); |
11808 | | int32_t num; |
11809 | | if (env) { |
11810 | | if (GetNumber(env, num)) |
11811 | | mAssert = num; |
11812 | | else |
11813 | | printf("GECKO_DISPLAY_REFLOW_ASSERT - invalid value = %s", env); |
11814 | | } |
11815 | | |
11816 | | env = PR_GetEnv("GECKO_DISPLAY_REFLOW_INDENT_START"); |
11817 | | if (env) { |
11818 | | if (GetNumber(env, num)) |
11819 | | mIndent = num; |
11820 | | else |
11821 | | printf("GECKO_DISPLAY_REFLOW_INDENT_START - invalid value = %s", env); |
11822 | | } |
11823 | | |
11824 | | env = PR_GetEnv("GECKO_DISPLAY_REFLOW_INDENT_UNDISPLAYED_FRAMES"); |
11825 | | if (env) { |
11826 | | if (GetNumber(env, num)) |
11827 | | mIndentUndisplayedFrames = num; |
11828 | | else |
11829 | | printf("GECKO_DISPLAY_REFLOW_INDENT_UNDISPLAYED_FRAMES - invalid value = %s", env); |
11830 | | } |
11831 | | |
11832 | | env = PR_GetEnv("GECKO_DISPLAY_REFLOW_FLAG_PIXEL_ERRORS"); |
11833 | | if (env) { |
11834 | | if (GetNumber(env, num)) |
11835 | | mDisplayPixelErrors = num; |
11836 | | else |
11837 | | printf("GECKO_DISPLAY_REFLOW_FLAG_PIXEL_ERRORS - invalid value = %s", env); |
11838 | | } |
11839 | | |
11840 | | InitFrameTypeTable(); |
11841 | | ParseRulesFile(); |
11842 | | mInited = true; |
11843 | | } |
11844 | | |
11845 | | DR_State::~DR_State() |
11846 | | { |
11847 | | MOZ_COUNT_DTOR(DR_State); |
11848 | | int32_t numElements, i; |
11849 | | numElements = mWildRules.Length(); |
11850 | | for (i = numElements - 1; i >= 0; i--) { |
11851 | | delete mWildRules.ElementAt(i); |
11852 | | } |
11853 | | numElements = mFrameTreeLeaves.Length(); |
11854 | | for (i = numElements - 1; i >= 0; i--) { |
11855 | | delete mFrameTreeLeaves.ElementAt(i); |
11856 | | } |
11857 | | } |
11858 | | |
11859 | | bool DR_State::GetNumber(char* aBuf, |
11860 | | int32_t& aNumber) |
11861 | | { |
11862 | | if (sscanf(aBuf, "%d", &aNumber) > 0) |
11863 | | return true; |
11864 | | else |
11865 | | return false; |
11866 | | } |
11867 | | |
11868 | | bool DR_State::IsWhiteSpace(int c) { |
11869 | | return (c == ' ') || (c == '\t') || (c == '\n') || (c == '\r'); |
11870 | | } |
11871 | | |
11872 | | bool DR_State::GetToken(FILE* aFile, |
11873 | | char* aBuf, |
11874 | | size_t aBufSize) |
11875 | | { |
11876 | | bool haveToken = false; |
11877 | | aBuf[0] = 0; |
11878 | | // get the 1st non whitespace char |
11879 | | int c = -1; |
11880 | | for (c = getc(aFile); (c > 0) && IsWhiteSpace(c); c = getc(aFile)) { |
11881 | | } |
11882 | | |
11883 | | if (c > 0) { |
11884 | | haveToken = true; |
11885 | | aBuf[0] = c; |
11886 | | // get everything up to the next whitespace char |
11887 | | size_t cX; |
11888 | | for (cX = 1; cX + 1 < aBufSize ; cX++) { |
11889 | | c = getc(aFile); |
11890 | | if (c < 0) { // EOF |
11891 | | ungetc(' ', aFile); |
11892 | | break; |
11893 | | } |
11894 | | else { |
11895 | | if (IsWhiteSpace(c)) { |
11896 | | break; |
11897 | | } |
11898 | | else { |
11899 | | aBuf[cX] = c; |
11900 | | } |
11901 | | } |
11902 | | } |
11903 | | aBuf[cX] = 0; |
11904 | | } |
11905 | | return haveToken; |
11906 | | } |
11907 | | |
11908 | | DR_Rule* DR_State::ParseRule(FILE* aFile) |
11909 | | { |
11910 | | char buf[128]; |
11911 | | int32_t doDisplay; |
11912 | | DR_Rule* rule = nullptr; |
11913 | | while (GetToken(aFile, buf, sizeof(buf))) { |
11914 | | if (GetNumber(buf, doDisplay)) { |
11915 | | if (rule) { |
11916 | | rule->mDisplay = !!doDisplay; |
11917 | | break; |
11918 | | } |
11919 | | else { |
11920 | | printf("unexpected token - %s \n", buf); |
11921 | | } |
11922 | | } |
11923 | | else { |
11924 | | if (!rule) { |
11925 | | rule = new DR_Rule; |
11926 | | } |
11927 | | if (strcmp(buf, "*") == 0) { |
11928 | | rule->AddPart(LayoutFrameType::None); |
11929 | | } |
11930 | | else { |
11931 | | DR_FrameTypeInfo* info = GetFrameTypeInfo(buf); |
11932 | | if (info) { |
11933 | | rule->AddPart(info->mType); |
11934 | | } |
11935 | | else { |
11936 | | printf("invalid frame type - %s \n", buf); |
11937 | | } |
11938 | | } |
11939 | | } |
11940 | | } |
11941 | | return rule; |
11942 | | } |
11943 | | |
11944 | | void DR_State::AddRule(nsTArray<DR_Rule*>& aRules, |
11945 | | DR_Rule& aRule) |
11946 | | { |
11947 | | int32_t numRules = aRules.Length(); |
11948 | | for (int32_t ruleX = 0; ruleX < numRules; ruleX++) { |
11949 | | DR_Rule* rule = aRules.ElementAt(ruleX); |
11950 | | NS_ASSERTION(rule, "program error"); |
11951 | | if (aRule.mLength > rule->mLength) { |
11952 | | aRules.InsertElementAt(ruleX, &aRule); |
11953 | | return; |
11954 | | } |
11955 | | } |
11956 | | aRules.AppendElement(&aRule); |
11957 | | } |
11958 | | |
11959 | | static Maybe<bool> ShouldLogReflow(const char* processes) |
11960 | | { |
11961 | | switch (processes[0]) { |
11962 | | case 'A': case 'a': return Some(true); |
11963 | | case 'P': case 'p': return Some(XRE_IsParentProcess()); |
11964 | | case 'C': case 'c': return Some(XRE_IsContentProcess()); |
11965 | | default: return Nothing{}; |
11966 | | } |
11967 | | } |
11968 | | |
11969 | | void DR_State::ParseRulesFile() |
11970 | | { |
11971 | | char* processes = PR_GetEnv("GECKO_DISPLAY_REFLOW_PROCESSES"); |
11972 | | if (processes) { |
11973 | | Maybe<bool> enableLog = ShouldLogReflow(processes); |
11974 | | if (enableLog.isNothing()) { |
11975 | | MOZ_CRASH("GECKO_DISPLAY_REFLOW_PROCESSES: [a]ll [p]arent [c]ontent"); |
11976 | | } else if (enableLog.value()) { |
11977 | | DR_Rule* rule = new DR_Rule; |
11978 | | rule->AddPart(LayoutFrameType::None); |
11979 | | rule->mDisplay = true; |
11980 | | AddRule(mWildRules, *rule); |
11981 | | mActive = true; |
11982 | | } |
11983 | | return; |
11984 | | } |
11985 | | |
11986 | | char* path = PR_GetEnv("GECKO_DISPLAY_REFLOW_RULES_FILE"); |
11987 | | if (path) { |
11988 | | FILE* inFile = fopen(path, "r"); |
11989 | | if (!inFile) { |
11990 | | MOZ_CRASH("Failed to open the specified rules file; Try `--setpref security.sandbox.content.level=2` if the sandbox is at cause"); |
11991 | | } |
11992 | | for (DR_Rule* rule = ParseRule(inFile); rule; rule = ParseRule(inFile)) { |
11993 | | if (rule->mTarget) { |
11994 | | LayoutFrameType fType = rule->mTarget->mFrameType; |
11995 | | if (fType != LayoutFrameType::None) { |
11996 | | DR_FrameTypeInfo* info = GetFrameTypeInfo(fType); |
11997 | | AddRule(info->mRules, *rule); |
11998 | | } |
11999 | | else { |
12000 | | AddRule(mWildRules, *rule); |
12001 | | } |
12002 | | mActive = true; |
12003 | | } |
12004 | | } |
12005 | | |
12006 | | fclose(inFile); |
12007 | | } |
12008 | | } |
12009 | | |
12010 | | void |
12011 | | DR_State::AddFrameTypeInfo(LayoutFrameType aFrameType, |
12012 | | const char* aFrameNameAbbrev, |
12013 | | const char* aFrameName) |
12014 | | { |
12015 | | mFrameTypeTable.AppendElement(DR_FrameTypeInfo(aFrameType, aFrameNameAbbrev, aFrameName)); |
12016 | | } |
12017 | | |
12018 | | DR_FrameTypeInfo* |
12019 | | DR_State::GetFrameTypeInfo(LayoutFrameType aFrameType) |
12020 | | { |
12021 | | int32_t numEntries = mFrameTypeTable.Length(); |
12022 | | NS_ASSERTION(numEntries != 0, "empty FrameTypeTable"); |
12023 | | for (int32_t i = 0; i < numEntries; i++) { |
12024 | | DR_FrameTypeInfo& info = mFrameTypeTable.ElementAt(i); |
12025 | | if (info.mType == aFrameType) { |
12026 | | return &info; |
12027 | | } |
12028 | | } |
12029 | | return &mFrameTypeTable.ElementAt(numEntries - 1); // return unknown frame type |
12030 | | } |
12031 | | |
12032 | | DR_FrameTypeInfo* DR_State::GetFrameTypeInfo(char* aFrameName) |
12033 | | { |
12034 | | int32_t numEntries = mFrameTypeTable.Length(); |
12035 | | NS_ASSERTION(numEntries != 0, "empty FrameTypeTable"); |
12036 | | for (int32_t i = 0; i < numEntries; i++) { |
12037 | | DR_FrameTypeInfo& info = mFrameTypeTable.ElementAt(i); |
12038 | | if ((strcmp(aFrameName, info.mName) == 0) || (strcmp(aFrameName, info.mNameAbbrev) == 0)) { |
12039 | | return &info; |
12040 | | } |
12041 | | } |
12042 | | return &mFrameTypeTable.ElementAt(numEntries - 1); // return unknown frame type |
12043 | | } |
12044 | | |
12045 | | void DR_State::InitFrameTypeTable() |
12046 | | { |
12047 | | AddFrameTypeInfo(LayoutFrameType::Block, "block", "block"); |
12048 | | AddFrameTypeInfo(LayoutFrameType::Br, "br", "br"); |
12049 | | AddFrameTypeInfo(LayoutFrameType::Bullet, "bullet", "bullet"); |
12050 | | AddFrameTypeInfo(LayoutFrameType::ColorControl, "color", "colorControl"); |
12051 | | AddFrameTypeInfo(LayoutFrameType::GfxButtonControl, "button", "gfxButtonControl"); |
12052 | | AddFrameTypeInfo(LayoutFrameType::HTMLButtonControl, "HTMLbutton", "HTMLButtonControl"); |
12053 | | AddFrameTypeInfo(LayoutFrameType::HTMLCanvas, "HTMLCanvas","HTMLCanvas"); |
12054 | | AddFrameTypeInfo(LayoutFrameType::SubDocument, "subdoc", "subDocument"); |
12055 | | AddFrameTypeInfo(LayoutFrameType::Image, "img", "image"); |
12056 | | AddFrameTypeInfo(LayoutFrameType::Inline, "inline", "inline"); |
12057 | | AddFrameTypeInfo(LayoutFrameType::Letter, "letter", "letter"); |
12058 | | AddFrameTypeInfo(LayoutFrameType::Line, "line", "line"); |
12059 | | AddFrameTypeInfo(LayoutFrameType::ListControl, "select", "select"); |
12060 | | AddFrameTypeInfo(LayoutFrameType::Object, "obj", "object"); |
12061 | | AddFrameTypeInfo(LayoutFrameType::Page, "page", "page"); |
12062 | | AddFrameTypeInfo(LayoutFrameType::Placeholder, "place", "placeholder"); |
12063 | | AddFrameTypeInfo(LayoutFrameType::Canvas, "canvas", "canvas"); |
12064 | | AddFrameTypeInfo(LayoutFrameType::Root, "root", "root"); |
12065 | | AddFrameTypeInfo(LayoutFrameType::Scroll, "scroll", "scroll"); |
12066 | | AddFrameTypeInfo(LayoutFrameType::TableCell, "cell", "tableCell"); |
12067 | | AddFrameTypeInfo(LayoutFrameType::BCTableCell, "bcCell", "bcTableCell"); |
12068 | | AddFrameTypeInfo(LayoutFrameType::TableCol, "col", "tableCol"); |
12069 | | AddFrameTypeInfo(LayoutFrameType::TableColGroup, "colG", "tableColGroup"); |
12070 | | AddFrameTypeInfo(LayoutFrameType::Table, "tbl", "table"); |
12071 | | AddFrameTypeInfo(LayoutFrameType::TableWrapper, "tblW", "tableWrapper"); |
12072 | | AddFrameTypeInfo(LayoutFrameType::TableRowGroup, "rowG", "tableRowGroup"); |
12073 | | AddFrameTypeInfo(LayoutFrameType::TableRow, "row", "tableRow"); |
12074 | | AddFrameTypeInfo(LayoutFrameType::TextInput, "textCtl", "textInput"); |
12075 | | AddFrameTypeInfo(LayoutFrameType::Text, "text", "text"); |
12076 | | AddFrameTypeInfo(LayoutFrameType::Viewport, "VP", "viewport"); |
12077 | | #ifdef MOZ_XUL |
12078 | | AddFrameTypeInfo(LayoutFrameType::XULLabel, "XULLabel", "XULLabel"); |
12079 | | AddFrameTypeInfo(LayoutFrameType::Box, "Box", "Box"); |
12080 | | AddFrameTypeInfo(LayoutFrameType::Slider, "Slider", "Slider"); |
12081 | | AddFrameTypeInfo(LayoutFrameType::PopupSet, "PopupSet", "PopupSet"); |
12082 | | #endif |
12083 | | AddFrameTypeInfo(LayoutFrameType::None, "unknown", "unknown"); |
12084 | | } |
12085 | | |
12086 | | |
12087 | | void DR_State::DisplayFrameTypeInfo(nsIFrame* aFrame, |
12088 | | int32_t aIndent) |
12089 | | { |
12090 | | DR_FrameTypeInfo* frameTypeInfo = GetFrameTypeInfo(aFrame->Type()); |
12091 | | if (frameTypeInfo) { |
12092 | | for (int32_t i = 0; i < aIndent; i++) { |
12093 | | printf(" "); |
12094 | | } |
12095 | | if(!strcmp(frameTypeInfo->mNameAbbrev, "unknown")) { |
12096 | | if (aFrame) { |
12097 | | nsAutoString name; |
12098 | | aFrame->GetFrameName(name); |
12099 | | printf("%s %p ", NS_LossyConvertUTF16toASCII(name).get(), (void*)aFrame); |
12100 | | } |
12101 | | else { |
12102 | | printf("%s %p ", frameTypeInfo->mNameAbbrev, (void*)aFrame); |
12103 | | } |
12104 | | } |
12105 | | else { |
12106 | | printf("%s %p ", frameTypeInfo->mNameAbbrev, (void*)aFrame); |
12107 | | } |
12108 | | } |
12109 | | } |
12110 | | |
12111 | | bool |
12112 | | DR_State::RuleMatches(DR_Rule& aRule, DR_FrameTreeNode& aNode) |
12113 | | { |
12114 | | NS_ASSERTION(aRule.mTarget, "program error"); |
12115 | | |
12116 | | DR_RulePart* rulePart; |
12117 | | DR_FrameTreeNode* parentNode; |
12118 | | for (rulePart = aRule.mTarget->mNext, parentNode = aNode.mParent; |
12119 | | rulePart && parentNode; |
12120 | | rulePart = rulePart->mNext, parentNode = parentNode->mParent) { |
12121 | | if (rulePart->mFrameType != LayoutFrameType::None) { |
12122 | | if (parentNode->mFrame) { |
12123 | | if (rulePart->mFrameType != parentNode->mFrame->Type()) { |
12124 | | return false; |
12125 | | } |
12126 | | } else NS_ASSERTION(false, "program error"); |
12127 | | } |
12128 | | // else wild card match |
12129 | | } |
12130 | | return true; |
12131 | | } |
12132 | | |
12133 | | void DR_State::FindMatchingRule(DR_FrameTreeNode& aNode) |
12134 | | { |
12135 | | if (!aNode.mFrame) { |
12136 | | NS_ASSERTION(false, "invalid DR_FrameTreeNode \n"); |
12137 | | return; |
12138 | | } |
12139 | | |
12140 | | bool matchingRule = false; |
12141 | | |
12142 | | DR_FrameTypeInfo* info = GetFrameTypeInfo(aNode.mFrame->Type()); |
12143 | | NS_ASSERTION(info, "program error"); |
12144 | | int32_t numRules = info->mRules.Length(); |
12145 | | for (int32_t ruleX = 0; ruleX < numRules; ruleX++) { |
12146 | | DR_Rule* rule = info->mRules.ElementAt(ruleX); |
12147 | | if (rule && RuleMatches(*rule, aNode)) { |
12148 | | aNode.mDisplay = rule->mDisplay; |
12149 | | matchingRule = true; |
12150 | | break; |
12151 | | } |
12152 | | } |
12153 | | if (!matchingRule) { |
12154 | | int32_t numWildRules = mWildRules.Length(); |
12155 | | for (int32_t ruleX = 0; ruleX < numWildRules; ruleX++) { |
12156 | | DR_Rule* rule = mWildRules.ElementAt(ruleX); |
12157 | | if (rule && RuleMatches(*rule, aNode)) { |
12158 | | aNode.mDisplay = rule->mDisplay; |
12159 | | break; |
12160 | | } |
12161 | | } |
12162 | | } |
12163 | | } |
12164 | | |
12165 | | DR_FrameTreeNode* DR_State::CreateTreeNode(nsIFrame* aFrame, |
12166 | | const ReflowInput* aReflowInput) |
12167 | | { |
12168 | | // find the frame of the parent reflow state (usually just the parent of aFrame) |
12169 | | nsIFrame* parentFrame; |
12170 | | if (aReflowInput) { |
12171 | | const ReflowInput* parentRI = aReflowInput->mParentReflowInput; |
12172 | | parentFrame = (parentRI) ? parentRI->mFrame : nullptr; |
12173 | | } else { |
12174 | | parentFrame = aFrame->GetParent(); |
12175 | | } |
12176 | | |
12177 | | // find the parent tree node leaf |
12178 | | DR_FrameTreeNode* parentNode = nullptr; |
12179 | | |
12180 | | DR_FrameTreeNode* lastLeaf = nullptr; |
12181 | | if(mFrameTreeLeaves.Length()) |
12182 | | lastLeaf = mFrameTreeLeaves.ElementAt(mFrameTreeLeaves.Length() - 1); |
12183 | | if (lastLeaf) { |
12184 | | for (parentNode = lastLeaf; parentNode && (parentNode->mFrame != parentFrame); parentNode = parentNode->mParent) { |
12185 | | } |
12186 | | } |
12187 | | DR_FrameTreeNode* newNode = new DR_FrameTreeNode(aFrame, parentNode); |
12188 | | FindMatchingRule(*newNode); |
12189 | | |
12190 | | newNode->mIndent = mIndent; |
12191 | | if (newNode->mDisplay || mIndentUndisplayedFrames) { |
12192 | | ++mIndent; |
12193 | | } |
12194 | | |
12195 | | if (lastLeaf && (lastLeaf == parentNode)) { |
12196 | | mFrameTreeLeaves.RemoveLastElement(); |
12197 | | } |
12198 | | mFrameTreeLeaves.AppendElement(newNode); |
12199 | | mCount++; |
12200 | | |
12201 | | return newNode; |
12202 | | } |
12203 | | |
12204 | | void DR_State::PrettyUC(nscoord aSize, |
12205 | | char* aBuf, |
12206 | | int aBufSize) |
12207 | | { |
12208 | | if (NS_UNCONSTRAINEDSIZE == aSize) { |
12209 | | strcpy(aBuf, "UC"); |
12210 | | } |
12211 | | else { |
12212 | | if ((nscoord)0xdeadbeefU == aSize) |
12213 | | { |
12214 | | strcpy(aBuf, "deadbeef"); |
12215 | | } |
12216 | | else { |
12217 | | snprintf(aBuf, aBufSize, "%d", aSize); |
12218 | | } |
12219 | | } |
12220 | | } |
12221 | | |
12222 | | void DR_State::PrintMargin(const char *tag, const nsMargin* aMargin) |
12223 | | { |
12224 | | if (aMargin) { |
12225 | | char t[16], r[16], b[16], l[16]; |
12226 | | PrettyUC(aMargin->top, t, 16); |
12227 | | PrettyUC(aMargin->right, r, 16); |
12228 | | PrettyUC(aMargin->bottom, b, 16); |
12229 | | PrettyUC(aMargin->left, l, 16); |
12230 | | printf(" %s=%s,%s,%s,%s", tag, t, r, b, l); |
12231 | | } else { |
12232 | | // use %p here for consistency with other null-pointer printouts |
12233 | | printf(" %s=%p", tag, (void*)aMargin); |
12234 | | } |
12235 | | } |
12236 | | |
12237 | | void DR_State::DeleteTreeNode(DR_FrameTreeNode& aNode) |
12238 | | { |
12239 | | mFrameTreeLeaves.RemoveElement(&aNode); |
12240 | | int32_t numLeaves = mFrameTreeLeaves.Length(); |
12241 | | if ((0 == numLeaves) || (aNode.mParent != mFrameTreeLeaves.ElementAt(numLeaves - 1))) { |
12242 | | mFrameTreeLeaves.AppendElement(aNode.mParent); |
12243 | | } |
12244 | | |
12245 | | if (aNode.mDisplay || mIndentUndisplayedFrames) { |
12246 | | --mIndent; |
12247 | | } |
12248 | | // delete the tree node |
12249 | | delete &aNode; |
12250 | | } |
12251 | | |
12252 | | static void |
12253 | | CheckPixelError(nscoord aSize, |
12254 | | int32_t aPixelToTwips) |
12255 | | { |
12256 | | if (NS_UNCONSTRAINEDSIZE != aSize) { |
12257 | | if ((aSize % aPixelToTwips) > 0) { |
12258 | | printf("VALUE %d is not a whole pixel \n", aSize); |
12259 | | } |
12260 | | } |
12261 | | } |
12262 | | |
12263 | | static void DisplayReflowEnterPrint(nsPresContext* aPresContext, |
12264 | | nsIFrame* aFrame, |
12265 | | const ReflowInput& aReflowInput, |
12266 | | DR_FrameTreeNode& aTreeNode, |
12267 | | bool aChanged) |
12268 | | { |
12269 | | if (aTreeNode.mDisplay) { |
12270 | | DR_state->DisplayFrameTypeInfo(aFrame, aTreeNode.mIndent); |
12271 | | |
12272 | | char width[16]; |
12273 | | char height[16]; |
12274 | | |
12275 | | DR_state->PrettyUC(aReflowInput.AvailableWidth(), width, 16); |
12276 | | DR_state->PrettyUC(aReflowInput.AvailableHeight(), height, 16); |
12277 | | printf("Reflow a=%s,%s ", width, height); |
12278 | | |
12279 | | DR_state->PrettyUC(aReflowInput.ComputedWidth(), width, 16); |
12280 | | DR_state->PrettyUC(aReflowInput.ComputedHeight(), height, 16); |
12281 | | printf("c=%s,%s ", width, height); |
12282 | | |
12283 | | if (aFrame->GetStateBits() & NS_FRAME_IS_DIRTY) |
12284 | | printf("dirty "); |
12285 | | |
12286 | | if (aFrame->GetStateBits() & NS_FRAME_HAS_DIRTY_CHILDREN) |
12287 | | printf("dirty-children "); |
12288 | | |
12289 | | if (aReflowInput.mFlags.mSpecialBSizeReflow) |
12290 | | printf("special-bsize "); |
12291 | | |
12292 | | if (aReflowInput.IsHResize()) |
12293 | | printf("h-resize "); |
12294 | | |
12295 | | if (aReflowInput.IsVResize()) |
12296 | | printf("v-resize "); |
12297 | | |
12298 | | nsIFrame* inFlow = aFrame->GetPrevInFlow(); |
12299 | | if (inFlow) { |
12300 | | printf("pif=%p ", (void*)inFlow); |
12301 | | } |
12302 | | inFlow = aFrame->GetNextInFlow(); |
12303 | | if (inFlow) { |
12304 | | printf("nif=%p ", (void*)inFlow); |
12305 | | } |
12306 | | if (aChanged) |
12307 | | printf("CHANGED \n"); |
12308 | | else |
12309 | | printf("cnt=%d \n", DR_state->mCount); |
12310 | | if (DR_state->mDisplayPixelErrors) { |
12311 | | int32_t d2a = aPresContext->AppUnitsPerDevPixel(); |
12312 | | CheckPixelError(aReflowInput.AvailableWidth(), d2a); |
12313 | | CheckPixelError(aReflowInput.AvailableHeight(), d2a); |
12314 | | CheckPixelError(aReflowInput.ComputedWidth(), d2a); |
12315 | | CheckPixelError(aReflowInput.ComputedHeight(), d2a); |
12316 | | } |
12317 | | } |
12318 | | } |
12319 | | |
12320 | | void* nsFrame::DisplayReflowEnter(nsPresContext* aPresContext, |
12321 | | nsIFrame* aFrame, |
12322 | | const ReflowInput& aReflowInput) |
12323 | | { |
12324 | | if (!DR_state->mInited) DR_state->Init(); |
12325 | | if (!DR_state->mActive) return nullptr; |
12326 | | |
12327 | | NS_ASSERTION(aFrame, "invalid call"); |
12328 | | |
12329 | | DR_FrameTreeNode* treeNode = DR_state->CreateTreeNode(aFrame, &aReflowInput); |
12330 | | if (treeNode) { |
12331 | | DisplayReflowEnterPrint(aPresContext, aFrame, aReflowInput, *treeNode, false); |
12332 | | } |
12333 | | return treeNode; |
12334 | | } |
12335 | | |
12336 | | void* nsFrame::DisplayLayoutEnter(nsIFrame* aFrame) |
12337 | | { |
12338 | | if (!DR_state->mInited) DR_state->Init(); |
12339 | | if (!DR_state->mActive) return nullptr; |
12340 | | |
12341 | | NS_ASSERTION(aFrame, "invalid call"); |
12342 | | |
12343 | | DR_FrameTreeNode* treeNode = DR_state->CreateTreeNode(aFrame, nullptr); |
12344 | | if (treeNode && treeNode->mDisplay) { |
12345 | | DR_state->DisplayFrameTypeInfo(aFrame, treeNode->mIndent); |
12346 | | printf("XULLayout\n"); |
12347 | | } |
12348 | | return treeNode; |
12349 | | } |
12350 | | |
12351 | | void* nsFrame::DisplayIntrinsicISizeEnter(nsIFrame* aFrame, |
12352 | | const char* aType) |
12353 | | { |
12354 | | if (!DR_state->mInited) DR_state->Init(); |
12355 | | if (!DR_state->mActive) return nullptr; |
12356 | | |
12357 | | NS_ASSERTION(aFrame, "invalid call"); |
12358 | | |
12359 | | DR_FrameTreeNode* treeNode = DR_state->CreateTreeNode(aFrame, nullptr); |
12360 | | if (treeNode && treeNode->mDisplay) { |
12361 | | DR_state->DisplayFrameTypeInfo(aFrame, treeNode->mIndent); |
12362 | | printf("Get%sISize\n", aType); |
12363 | | } |
12364 | | return treeNode; |
12365 | | } |
12366 | | |
12367 | | void* nsFrame::DisplayIntrinsicSizeEnter(nsIFrame* aFrame, |
12368 | | const char* aType) |
12369 | | { |
12370 | | if (!DR_state->mInited) DR_state->Init(); |
12371 | | if (!DR_state->mActive) return nullptr; |
12372 | | |
12373 | | NS_ASSERTION(aFrame, "invalid call"); |
12374 | | |
12375 | | DR_FrameTreeNode* treeNode = DR_state->CreateTreeNode(aFrame, nullptr); |
12376 | | if (treeNode && treeNode->mDisplay) { |
12377 | | DR_state->DisplayFrameTypeInfo(aFrame, treeNode->mIndent); |
12378 | | printf("Get%sSize\n", aType); |
12379 | | } |
12380 | | return treeNode; |
12381 | | } |
12382 | | |
12383 | | void nsFrame::DisplayReflowExit(nsPresContext* aPresContext, |
12384 | | nsIFrame* aFrame, |
12385 | | ReflowOutput& aMetrics, |
12386 | | const nsReflowStatus& aStatus, |
12387 | | void* aFrameTreeNode) |
12388 | | { |
12389 | | if (!DR_state->mActive) return; |
12390 | | |
12391 | | NS_ASSERTION(aFrame, "DisplayReflowExit - invalid call"); |
12392 | | if (!aFrameTreeNode) return; |
12393 | | |
12394 | | DR_FrameTreeNode* treeNode = (DR_FrameTreeNode*)aFrameTreeNode; |
12395 | | if (treeNode->mDisplay) { |
12396 | | DR_state->DisplayFrameTypeInfo(aFrame, treeNode->mIndent); |
12397 | | |
12398 | | char width[16]; |
12399 | | char height[16]; |
12400 | | char x[16]; |
12401 | | char y[16]; |
12402 | | DR_state->PrettyUC(aMetrics.Width(), width, 16); |
12403 | | DR_state->PrettyUC(aMetrics.Height(), height, 16); |
12404 | | printf("Reflow d=%s,%s", width, height); |
12405 | | |
12406 | | if (!aStatus.IsEmpty()) { |
12407 | | printf(" status=%s", ToString(aStatus).c_str()); |
12408 | | } |
12409 | | if (aFrame->HasOverflowAreas()) { |
12410 | | DR_state->PrettyUC(aMetrics.VisualOverflow().x, x, 16); |
12411 | | DR_state->PrettyUC(aMetrics.VisualOverflow().y, y, 16); |
12412 | | DR_state->PrettyUC(aMetrics.VisualOverflow().width, width, 16); |
12413 | | DR_state->PrettyUC(aMetrics.VisualOverflow().height, height, 16); |
12414 | | printf(" vis-o=(%s,%s) %s x %s", x, y, width, height); |
12415 | | |
12416 | | nsRect storedOverflow = aFrame->GetVisualOverflowRect(); |
12417 | | DR_state->PrettyUC(storedOverflow.x, x, 16); |
12418 | | DR_state->PrettyUC(storedOverflow.y, y, 16); |
12419 | | DR_state->PrettyUC(storedOverflow.width, width, 16); |
12420 | | DR_state->PrettyUC(storedOverflow.height, height, 16); |
12421 | | printf(" vis-sto=(%s,%s) %s x %s", x, y, width, height); |
12422 | | |
12423 | | DR_state->PrettyUC(aMetrics.ScrollableOverflow().x, x, 16); |
12424 | | DR_state->PrettyUC(aMetrics.ScrollableOverflow().y, y, 16); |
12425 | | DR_state->PrettyUC(aMetrics.ScrollableOverflow().width, width, 16); |
12426 | | DR_state->PrettyUC(aMetrics.ScrollableOverflow().height, height, 16); |
12427 | | printf(" scr-o=(%s,%s) %s x %s", x, y, width, height); |
12428 | | |
12429 | | storedOverflow = aFrame->GetScrollableOverflowRect(); |
12430 | | DR_state->PrettyUC(storedOverflow.x, x, 16); |
12431 | | DR_state->PrettyUC(storedOverflow.y, y, 16); |
12432 | | DR_state->PrettyUC(storedOverflow.width, width, 16); |
12433 | | DR_state->PrettyUC(storedOverflow.height, height, 16); |
12434 | | printf(" scr-sto=(%s,%s) %s x %s", x, y, width, height); |
12435 | | } |
12436 | | printf("\n"); |
12437 | | if (DR_state->mDisplayPixelErrors) { |
12438 | | int32_t d2a = aPresContext->AppUnitsPerDevPixel(); |
12439 | | CheckPixelError(aMetrics.Width(), d2a); |
12440 | | CheckPixelError(aMetrics.Height(), d2a); |
12441 | | } |
12442 | | } |
12443 | | DR_state->DeleteTreeNode(*treeNode); |
12444 | | } |
12445 | | |
12446 | | void nsFrame::DisplayLayoutExit(nsIFrame* aFrame, |
12447 | | void* aFrameTreeNode) |
12448 | | { |
12449 | | if (!DR_state->mActive) return; |
12450 | | |
12451 | | NS_ASSERTION(aFrame, "non-null frame required"); |
12452 | | if (!aFrameTreeNode) return; |
12453 | | |
12454 | | DR_FrameTreeNode* treeNode = (DR_FrameTreeNode*)aFrameTreeNode; |
12455 | | if (treeNode->mDisplay) { |
12456 | | DR_state->DisplayFrameTypeInfo(aFrame, treeNode->mIndent); |
12457 | | nsRect rect = aFrame->GetRect(); |
12458 | | printf("XULLayout=%d,%d,%d,%d\n", rect.x, rect.y, rect.width, rect.height); |
12459 | | } |
12460 | | DR_state->DeleteTreeNode(*treeNode); |
12461 | | } |
12462 | | |
12463 | | void nsFrame::DisplayIntrinsicISizeExit(nsIFrame* aFrame, |
12464 | | const char* aType, |
12465 | | nscoord aResult, |
12466 | | void* aFrameTreeNode) |
12467 | | { |
12468 | | if (!DR_state->mActive) return; |
12469 | | |
12470 | | NS_ASSERTION(aFrame, "non-null frame required"); |
12471 | | if (!aFrameTreeNode) return; |
12472 | | |
12473 | | DR_FrameTreeNode* treeNode = (DR_FrameTreeNode*)aFrameTreeNode; |
12474 | | if (treeNode->mDisplay) { |
12475 | | DR_state->DisplayFrameTypeInfo(aFrame, treeNode->mIndent); |
12476 | | char iSize[16]; |
12477 | | DR_state->PrettyUC(aResult, iSize, 16); |
12478 | | printf("Get%sISize=%s\n", aType, iSize); |
12479 | | } |
12480 | | DR_state->DeleteTreeNode(*treeNode); |
12481 | | } |
12482 | | |
12483 | | void nsFrame::DisplayIntrinsicSizeExit(nsIFrame* aFrame, |
12484 | | const char* aType, |
12485 | | nsSize aResult, |
12486 | | void* aFrameTreeNode) |
12487 | | { |
12488 | | if (!DR_state->mActive) return; |
12489 | | |
12490 | | NS_ASSERTION(aFrame, "non-null frame required"); |
12491 | | if (!aFrameTreeNode) return; |
12492 | | |
12493 | | DR_FrameTreeNode* treeNode = (DR_FrameTreeNode*)aFrameTreeNode; |
12494 | | if (treeNode->mDisplay) { |
12495 | | DR_state->DisplayFrameTypeInfo(aFrame, treeNode->mIndent); |
12496 | | |
12497 | | char width[16]; |
12498 | | char height[16]; |
12499 | | DR_state->PrettyUC(aResult.width, width, 16); |
12500 | | DR_state->PrettyUC(aResult.height, height, 16); |
12501 | | printf("Get%sSize=%s,%s\n", aType, width, height); |
12502 | | } |
12503 | | DR_state->DeleteTreeNode(*treeNode); |
12504 | | } |
12505 | | |
12506 | | /* static */ void |
12507 | | nsFrame::DisplayReflowStartup() |
12508 | | { |
12509 | | DR_state = new DR_State(); |
12510 | | } |
12511 | | |
12512 | | /* static */ void |
12513 | | nsFrame::DisplayReflowShutdown() |
12514 | | { |
12515 | | delete DR_state; |
12516 | | DR_state = nullptr; |
12517 | | } |
12518 | | |
12519 | | void DR_cookie::Change() const |
12520 | | { |
12521 | | DR_FrameTreeNode* treeNode = (DR_FrameTreeNode*)mValue; |
12522 | | if (treeNode && treeNode->mDisplay) { |
12523 | | DisplayReflowEnterPrint(mPresContext, mFrame, mReflowInput, *treeNode, true); |
12524 | | } |
12525 | | } |
12526 | | |
12527 | | /* static */ void* |
12528 | | ReflowInput::DisplayInitConstraintsEnter(nsIFrame* aFrame, |
12529 | | ReflowInput* aState, |
12530 | | nscoord aContainingBlockWidth, |
12531 | | nscoord aContainingBlockHeight, |
12532 | | const nsMargin* aBorder, |
12533 | | const nsMargin* aPadding) |
12534 | | { |
12535 | | MOZ_ASSERT(aFrame, "non-null frame required"); |
12536 | | MOZ_ASSERT(aState, "non-null state required"); |
12537 | | |
12538 | | if (!DR_state->mInited) DR_state->Init(); |
12539 | | if (!DR_state->mActive) return nullptr; |
12540 | | |
12541 | | DR_FrameTreeNode* treeNode = DR_state->CreateTreeNode(aFrame, aState); |
12542 | | if (treeNode && treeNode->mDisplay) { |
12543 | | DR_state->DisplayFrameTypeInfo(aFrame, treeNode->mIndent); |
12544 | | |
12545 | | printf("InitConstraints parent=%p", |
12546 | | (void*)aState->mParentReflowInput); |
12547 | | |
12548 | | char width[16]; |
12549 | | char height[16]; |
12550 | | |
12551 | | DR_state->PrettyUC(aContainingBlockWidth, width, 16); |
12552 | | DR_state->PrettyUC(aContainingBlockHeight, height, 16); |
12553 | | printf(" cb=%s,%s", width, height); |
12554 | | |
12555 | | DR_state->PrettyUC(aState->AvailableWidth(), width, 16); |
12556 | | DR_state->PrettyUC(aState->AvailableHeight(), height, 16); |
12557 | | printf(" as=%s,%s", width, height); |
12558 | | |
12559 | | DR_state->PrintMargin("b", aBorder); |
12560 | | DR_state->PrintMargin("p", aPadding); |
12561 | | putchar('\n'); |
12562 | | } |
12563 | | return treeNode; |
12564 | | } |
12565 | | |
12566 | | /* static */ void |
12567 | | ReflowInput::DisplayInitConstraintsExit(nsIFrame* aFrame, |
12568 | | ReflowInput* aState, |
12569 | | void* aValue) |
12570 | | { |
12571 | | MOZ_ASSERT(aFrame, "non-null frame required"); |
12572 | | MOZ_ASSERT(aState, "non-null state required"); |
12573 | | |
12574 | | if (!DR_state->mActive) return; |
12575 | | if (!aValue) return; |
12576 | | |
12577 | | DR_FrameTreeNode* treeNode = (DR_FrameTreeNode*)aValue; |
12578 | | if (treeNode->mDisplay) { |
12579 | | DR_state->DisplayFrameTypeInfo(aFrame, treeNode->mIndent); |
12580 | | char cmiw[16], cw[16], cmxw[16], cmih[16], ch[16], cmxh[16]; |
12581 | | DR_state->PrettyUC(aState->ComputedMinWidth(), cmiw, 16); |
12582 | | DR_state->PrettyUC(aState->ComputedWidth(), cw, 16); |
12583 | | DR_state->PrettyUC(aState->ComputedMaxWidth(), cmxw, 16); |
12584 | | DR_state->PrettyUC(aState->ComputedMinHeight(), cmih, 16); |
12585 | | DR_state->PrettyUC(aState->ComputedHeight(), ch, 16); |
12586 | | DR_state->PrettyUC(aState->ComputedMaxHeight(), cmxh, 16); |
12587 | | printf("InitConstraints= cw=(%s <= %s <= %s) ch=(%s <= %s <= %s)", |
12588 | | cmiw, cw, cmxw, cmih, ch, cmxh); |
12589 | | DR_state->PrintMargin("co", &aState->ComputedPhysicalOffsets()); |
12590 | | putchar('\n'); |
12591 | | } |
12592 | | DR_state->DeleteTreeNode(*treeNode); |
12593 | | } |
12594 | | |
12595 | | |
12596 | | /* static */ void* |
12597 | | SizeComputationInput::DisplayInitOffsetsEnter(nsIFrame* aFrame, |
12598 | | SizeComputationInput* aState, |
12599 | | nscoord aPercentBasis, |
12600 | | WritingMode aCBWritingMode, |
12601 | | const nsMargin* aBorder, |
12602 | | const nsMargin* aPadding) |
12603 | | { |
12604 | | MOZ_ASSERT(aFrame, "non-null frame required"); |
12605 | | MOZ_ASSERT(aState, "non-null state required"); |
12606 | | |
12607 | | if (!DR_state->mInited) DR_state->Init(); |
12608 | | if (!DR_state->mActive) return nullptr; |
12609 | | |
12610 | | // aState is not necessarily a ReflowInput |
12611 | | DR_FrameTreeNode* treeNode = DR_state->CreateTreeNode(aFrame, nullptr); |
12612 | | if (treeNode && treeNode->mDisplay) { |
12613 | | DR_state->DisplayFrameTypeInfo(aFrame, treeNode->mIndent); |
12614 | | |
12615 | | char pctBasisStr[16]; |
12616 | | DR_state->PrettyUC(aPercentBasis, pctBasisStr, 16); |
12617 | | printf("InitOffsets pct_basis=%s", pctBasisStr); |
12618 | | |
12619 | | DR_state->PrintMargin("b", aBorder); |
12620 | | DR_state->PrintMargin("p", aPadding); |
12621 | | putchar('\n'); |
12622 | | } |
12623 | | return treeNode; |
12624 | | } |
12625 | | |
12626 | | /* static */ void |
12627 | | SizeComputationInput::DisplayInitOffsetsExit(nsIFrame* aFrame, |
12628 | | SizeComputationInput* aState, |
12629 | | void* aValue) |
12630 | | { |
12631 | | MOZ_ASSERT(aFrame, "non-null frame required"); |
12632 | | MOZ_ASSERT(aState, "non-null state required"); |
12633 | | |
12634 | | if (!DR_state->mActive) return; |
12635 | | if (!aValue) return; |
12636 | | |
12637 | | DR_FrameTreeNode* treeNode = (DR_FrameTreeNode*)aValue; |
12638 | | if (treeNode->mDisplay) { |
12639 | | DR_state->DisplayFrameTypeInfo(aFrame, treeNode->mIndent); |
12640 | | printf("InitOffsets="); |
12641 | | DR_state->PrintMargin("m", &aState->ComputedPhysicalMargin()); |
12642 | | DR_state->PrintMargin("p", &aState->ComputedPhysicalPadding()); |
12643 | | DR_state->PrintMargin("p+b", &aState->ComputedPhysicalBorderPadding()); |
12644 | | putchar('\n'); |
12645 | | } |
12646 | | DR_state->DeleteTreeNode(*treeNode); |
12647 | | } |
12648 | | |
12649 | | /* static */ void* |
12650 | | ReflowInput::DisplayInitFrameTypeEnter(nsIFrame* aFrame, |
12651 | | ReflowInput* aState) |
12652 | | { |
12653 | | MOZ_ASSERT(aFrame, "non-null frame required"); |
12654 | | MOZ_ASSERT(aState, "non-null state required"); |
12655 | | |
12656 | | if (!DR_state->mInited) DR_state->Init(); |
12657 | | if (!DR_state->mActive) return nullptr; |
12658 | | |
12659 | | // we don't print anything here |
12660 | | return DR_state->CreateTreeNode(aFrame, aState); |
12661 | | } |
12662 | | |
12663 | | /* static */ void |
12664 | | ReflowInput::DisplayInitFrameTypeExit(nsIFrame* aFrame, |
12665 | | ReflowInput* aState, |
12666 | | void* aValue) |
12667 | | { |
12668 | | MOZ_ASSERT(aFrame, "non-null frame required"); |
12669 | | MOZ_ASSERT(aState, "non-null state required"); |
12670 | | |
12671 | | if (!DR_state->mActive) return; |
12672 | | if (!aValue) return; |
12673 | | |
12674 | | DR_FrameTreeNode* treeNode = (DR_FrameTreeNode*)aValue; |
12675 | | if (treeNode->mDisplay) { |
12676 | | DR_state->DisplayFrameTypeInfo(aFrame, treeNode->mIndent); |
12677 | | printf("InitFrameType"); |
12678 | | |
12679 | | const nsStyleDisplay *disp = aState->mStyleDisplay; |
12680 | | |
12681 | | if (aFrame->GetStateBits() & NS_FRAME_OUT_OF_FLOW) |
12682 | | printf(" out-of-flow"); |
12683 | | if (aFrame->GetPrevInFlow()) |
12684 | | printf(" prev-in-flow"); |
12685 | | if (aFrame->IsAbsolutelyPositioned()) |
12686 | | printf(" abspos"); |
12687 | | if (aFrame->IsFloating()) |
12688 | | printf(" float"); |
12689 | | |
12690 | | const nsCSSKeyword displayVal = |
12691 | | nsCSSProps::ValueToKeywordEnum(disp->mDisplay, |
12692 | | nsCSSProps::kDisplayKTable); |
12693 | | if (displayVal == eCSSKeyword_UNKNOWN) |
12694 | | printf(" display=%u", static_cast<uint32_t>(disp->mDisplay)); |
12695 | | else |
12696 | | printf(" display=%s", nsCSSKeywords::GetStringValue(displayVal).get()); |
12697 | | |
12698 | | // This array must exactly match the NS_CSS_FRAME_TYPE constants. |
12699 | | const char *const cssFrameTypes[] = { |
12700 | | "unknown", "inline", "block", "floating", "absolute", "internal-table" |
12701 | | }; |
12702 | | nsCSSFrameType bareType = NS_FRAME_GET_TYPE(aState->mFrameType); |
12703 | | bool repNoBlock = NS_FRAME_IS_REPLACED_NOBLOCK(aState->mFrameType); |
12704 | | bool repBlock = NS_FRAME_IS_REPLACED_CONTAINS_BLOCK(aState->mFrameType); |
12705 | | |
12706 | | if (bareType >= ArrayLength(cssFrameTypes)) { |
12707 | | printf(" result=type %u", bareType); |
12708 | | } else { |
12709 | | printf(" result=%s", cssFrameTypes[bareType]); |
12710 | | } |
12711 | | printf("%s%s\n", repNoBlock ? " +rep" : "", repBlock ? " +repBlk" : ""); |
12712 | | } |
12713 | | DR_state->DeleteTreeNode(*treeNode); |
12714 | | } |
12715 | | |
12716 | | #endif |
12717 | | // End Display Reflow |
12718 | | |
12719 | | #endif |