Line data Source code
1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 : * This Source Code Form is subject to the terms of the Mozilla Public
3 : * License, v. 2.0. If a copy of the MPL was not distributed with this
4 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 : *
6 : * This Original Code has been modified by IBM Corporation.
7 : * Modifications made by IBM described herein are
8 : * Copyright (c) International Business Machines
9 : * Corporation, 2000
10 : *
11 : * Modifications to Mozilla code or documentation
12 : * identified per MPL Section 3.3
13 : *
14 : * Date Modified by Description of modification
15 : * 05/03/2000 IBM Corp. Observer related defines for reflow
16 : */
17 :
18 : /* a presentation of a document, part 2 */
19 :
20 : #ifndef nsIPresShell_h___
21 : #define nsIPresShell_h___
22 :
23 : #include "mozilla/ArenaObjectID.h"
24 : #include "mozilla/EventForwards.h"
25 : #include "mozilla/FlushType.h"
26 : #include "mozilla/layers/FocusTarget.h"
27 : #include "mozilla/MemoryReporting.h"
28 : #include "mozilla/StaticPtr.h"
29 : #include "mozilla/StyleSetHandle.h"
30 : #include "mozilla/StyleSheet.h"
31 : #include "mozilla/WeakPtr.h"
32 : #include "gfxPoint.h"
33 : #include "nsTHashtable.h"
34 : #include "nsHashKeys.h"
35 : #include "nsISupports.h"
36 : #include "nsIContent.h"
37 : #include "nsISelectionController.h"
38 : #include "nsQueryFrame.h"
39 : #include "nsCoord.h"
40 : #include "nsColor.h"
41 : #include "nsFrameManagerBase.h"
42 : #include "nsRect.h"
43 : #include "nsRegionFwd.h"
44 : #include "nsWeakReference.h"
45 : #include <stdio.h> // for FILE definition
46 : #include "nsChangeHint.h"
47 : #include "nsRefPtrHashtable.h"
48 : #include "nsClassHashtable.h"
49 : #include "nsPresArena.h"
50 : #include "nsIImageLoadingContent.h"
51 : #include "nsMargin.h"
52 : #include "nsFrameState.h"
53 : #include "Units.h"
54 :
55 : class gfxContext;
56 : class nsDocShell;
57 : class nsIDocument;
58 : class nsIFrame;
59 : class nsPresContext;
60 : class nsViewManager;
61 : class nsView;
62 : class nsIPageSequenceFrame;
63 : class nsCanvasFrame;
64 : class nsAString;
65 : class nsCaret;
66 : namespace mozilla {
67 : class AccessibleCaretEventHub;
68 : class CSSStyleSheet;
69 : } // namespace mozilla
70 : class nsFrameSelection;
71 : class nsFrameManager;
72 : class nsILayoutHistoryState;
73 : class nsIReflowCallback;
74 : class nsIDOMNode;
75 : class nsCSSFrameConstructor;
76 : class nsISelection;
77 : template<class E> class nsCOMArray;
78 : class AutoWeakFrame;
79 : class WeakFrame;
80 : class nsIScrollableFrame;
81 : class nsIDOMEvent;
82 : class nsDisplayList;
83 : class nsDisplayListBuilder;
84 : class nsPIDOMWindowOuter;
85 : struct nsPoint;
86 : class nsINode;
87 : struct nsRect;
88 : class nsRegion;
89 : class nsRefreshDriver;
90 : class nsARefreshObserver;
91 : class nsAPostRefreshObserver;
92 : #ifdef ACCESSIBILITY
93 : class nsAccessibilityService;
94 : namespace mozilla {
95 : namespace a11y {
96 : class DocAccessible;
97 : } // namespace a11y
98 : } // namespace mozilla
99 : #endif
100 : struct nsArenaMemoryStats;
101 : class nsITimer;
102 :
103 : namespace mozilla {
104 : class EventStates;
105 :
106 : namespace dom {
107 : class Element;
108 : class Touch;
109 : class Selection;
110 : class ShadowRoot;
111 : } // namespace dom
112 :
113 : namespace layers {
114 : class LayerManager;
115 : } // namespace layers
116 :
117 : namespace gfx {
118 : class SourceSurface;
119 : } // namespace gfx
120 : } // namespace mozilla
121 :
122 : // Flags to pass to SetCapturingContent
123 : //
124 : // when assigning capture, ignore whether capture is allowed or not
125 : #define CAPTURE_IGNOREALLOWED 1
126 : // true if events should be targeted at the capturing content or its children
127 : #define CAPTURE_RETARGETTOELEMENT 2
128 : // true if the current capture wants drags to be prevented
129 : #define CAPTURE_PREVENTDRAG 4
130 : // true when the mouse is pointer locked, and events are sent to locked element
131 : #define CAPTURE_POINTERLOCK 8
132 :
133 : typedef struct CapturingContentInfo {
134 : // capture should only be allowed during a mousedown event
135 : bool mAllowed;
136 : bool mPointerLock;
137 : bool mRetargetToElement;
138 : bool mPreventDrag;
139 : mozilla::StaticRefPtr<nsIContent> mContent;
140 : } CapturingContentInfo;
141 :
142 : // a75573d6-34c8-4485-8fb7-edcb6fc70e12
143 : #define NS_IPRESSHELL_IID \
144 : { 0xa75573d6, 0x34c8, 0x4485, \
145 : { 0x8f, 0xb7, 0xed, 0xcb, 0x6f, 0xc7, 0x0e, 0x12 } }
146 :
147 : // debug VerifyReflow flags
148 : #define VERIFY_REFLOW_ON 0x01
149 : #define VERIFY_REFLOW_NOISY 0x02
150 : #define VERIFY_REFLOW_ALL 0x04
151 : #define VERIFY_REFLOW_DUMP_COMMANDS 0x08
152 : #define VERIFY_REFLOW_NOISY_RC 0x10
153 : #define VERIFY_REFLOW_REALLY_NOISY_RC 0x20
154 : #define VERIFY_REFLOW_DURING_RESIZE_REFLOW 0x40
155 :
156 : #undef NOISY_INTERRUPTIBLE_REFLOW
157 :
158 : enum nsRectVisibility {
159 : nsRectVisibility_kVisible,
160 : nsRectVisibility_kAboveViewport,
161 : nsRectVisibility_kBelowViewport,
162 : nsRectVisibility_kLeftOfViewport,
163 : nsRectVisibility_kRightOfViewport
164 : };
165 :
166 : /**
167 : * Presentation shell interface. Presentation shells are the
168 : * controlling point for managing the presentation of a document. The
169 : * presentation shell holds a live reference to the document, the
170 : * presentation context, the style manager, the style set and the root
171 : * frame. <p>
172 : *
173 : * When this object is Release'd, it will release the document, the
174 : * presentation context, the style manager, the style set and the root
175 : * frame.
176 : */
177 :
178 4 : class nsIPresShell : public nsISupports
179 : {
180 : public:
181 : NS_DECLARE_STATIC_IID_ACCESSOR(NS_IPRESSHELL_IID)
182 :
183 : protected:
184 : typedef mozilla::layers::FocusTarget FocusTarget;
185 : typedef mozilla::layers::LayerManager LayerManager;
186 : typedef mozilla::gfx::SourceSurface SourceSurface;
187 :
188 : enum eRenderFlag {
189 : STATE_IGNORING_VIEWPORT_SCROLLING = 0x1,
190 : STATE_DRAWWINDOW_NOT_FLUSHING = 0x2
191 : };
192 : typedef uint8_t RenderFlags; // for storing the above flags
193 :
194 : public:
195 : nsIPresShell();
196 :
197 : /**
198 : * All callers are responsible for calling |Destroy| after calling
199 : * |EndObservingDocument|. It needs to be separate only because form
200 : * controls incorrectly store their data in the frames rather than the
201 : * content model and printing calls |EndObservingDocument| multiple
202 : * times to make form controls behave nicely when printed.
203 : */
204 : virtual void Destroy() = 0;
205 :
206 778 : bool IsDestroying() { return mIsDestroying; }
207 :
208 : /**
209 : * All frames owned by the shell are allocated from an arena. They
210 : * are also recycled using free lists. Separate free lists are
211 : * maintained for each frame type (aID), which must always correspond
212 : * to the same aSize value. AllocateFrame is infallible and will abort
213 : * on out-of-memory.
214 : */
215 666 : void* AllocateFrame(nsQueryFrame::FrameIID aID, size_t aSize)
216 : {
217 666 : void* result = mFrameArena.AllocateByFrameID(aID, aSize);
218 666 : RecordAlloc(result);
219 666 : return result;
220 : }
221 :
222 126 : void FreeFrame(nsQueryFrame::FrameIID aID, void* aPtr)
223 : {
224 126 : RecordFree(aPtr);
225 126 : if (!mIsDestroying)
226 126 : mFrameArena.FreeByFrameID(aID, aPtr);
227 126 : }
228 :
229 : /**
230 : * This is for allocating other types of objects (not frames). Separate free
231 : * lists are maintained for each type (aID), which must always correspond to
232 : * the same aSize value. AllocateByObjectID is infallible and will abort on
233 : * out-of-memory.
234 : */
235 11293 : void* AllocateByObjectID(mozilla::ArenaObjectID aID, size_t aSize)
236 : {
237 11293 : void* result = mFrameArena.AllocateByObjectID(aID, aSize);
238 11293 : RecordAlloc(result);
239 11293 : return result;
240 : }
241 :
242 6730 : void FreeByObjectID(mozilla::ArenaObjectID aID, void* aPtr)
243 : {
244 6730 : RecordFree(aPtr);
245 6730 : if (!mIsDestroying)
246 6726 : mFrameArena.FreeByObjectID(aID, aPtr);
247 6730 : }
248 :
249 : template<typename T>
250 4 : void RegisterArenaRefPtr(mozilla::ArenaRefPtr<T>* aPtr)
251 : {
252 4 : mFrameArena.RegisterArenaRefPtr(aPtr);
253 4 : }
254 :
255 : template<typename T>
256 4 : void DeregisterArenaRefPtr(mozilla::ArenaRefPtr<T>* aPtr)
257 : {
258 4 : mFrameArena.DeregisterArenaRefPtr(aPtr);
259 4 : }
260 :
261 2 : void ClearArenaRefPtrs(mozilla::ArenaObjectID aObjectID)
262 : {
263 2 : mFrameArena.ClearArenaRefPtrs(aObjectID);
264 2 : }
265 :
266 23138 : nsIDocument* GetDocument() const { return mDocument; }
267 :
268 5331 : nsPresContext* GetPresContext() const { return mPresContext; }
269 :
270 17203 : nsViewManager* GetViewManager() const { return mViewManager; }
271 :
272 : nsRefreshDriver* GetRefreshDriver() const;
273 :
274 : #ifdef ACCESSIBILITY
275 : /**
276 : * Return the document accessible for this pres shell if there is one.
277 : */
278 0 : mozilla::a11y::DocAccessible* GetDocAccessible() const
279 : {
280 0 : return mDocAccessible;
281 : }
282 :
283 : /**
284 : * Set the document accessible for this pres shell.
285 : */
286 0 : void SetDocAccessible(mozilla::a11y::DocAccessible* aDocAccessible)
287 : {
288 0 : mDocAccessible = aDocAccessible;
289 0 : }
290 : #endif
291 :
292 : #ifdef MOZILLA_INTERNAL_API
293 22002 : mozilla::StyleSetHandle StyleSet() const { return mStyleSet; }
294 :
295 2571 : nsCSSFrameConstructor* FrameConstructor() const { return mFrameConstructor; }
296 :
297 5152 : nsFrameManager* FrameManager() const {
298 : // reinterpret_cast is valid since nsFrameManager does not add
299 : // any members over nsFrameManagerBase.
300 : return reinterpret_cast<nsFrameManager*>
301 5152 : (const_cast<nsIPresShell*>(this)->mFrameManager);
302 : }
303 :
304 : #endif
305 :
306 : /* Enable/disable author style level. Disabling author style disables the entire
307 : * author level of the cascade, including the HTML preshint level.
308 : */
309 : // XXX these could easily be inlined, but there is a circular #include
310 : // problem with nsStyleSet.
311 : void SetAuthorStyleDisabled(bool aDisabled);
312 : bool GetAuthorStyleDisabled() const;
313 :
314 : /*
315 : * Called when stylesheets are added/removed/enabled/disabled to
316 : * recompute style and clear other cached data as needed. This will
317 : * not reconstruct style synchronously; if you need to do that, call
318 : * FlushPendingNotifications to flush out style reresolves.
319 : *
320 : * This handles the the addition and removal of the various types of
321 : * style rules that can be in CSS style sheets, such as @font-face
322 : * rules and @counter-style rules.
323 : *
324 : * It requires that StyleSheetAdded, StyleSheetRemoved,
325 : * StyleSheetApplicableStateChanged, StyleRuleAdded, StyleRuleRemoved,
326 : * or StyleRuleChanged has been called on the style sheets that have
327 : * changed.
328 : *
329 : * // XXXbz why do we have this on the interface anyway? The only consumer
330 : * is calling AddOverrideStyleSheet/RemoveOverrideStyleSheet, and I think
331 : * those should just handle reconstructing style data...
332 : */
333 : void RestyleForCSSRuleChanges();
334 :
335 : /**
336 : * Update the style set somehow to take into account changed prefs which
337 : * affect document styling.
338 : */
339 : virtual void UpdatePreferenceStyles() = 0;
340 :
341 : /**
342 : * FrameSelection will return the Frame based selection API.
343 : * You cannot go back and forth anymore with QI between nsIDOM sel and
344 : * nsIFrame sel.
345 : */
346 : already_AddRefed<nsFrameSelection> FrameSelection();
347 :
348 : /**
349 : * ConstFrameSelection returns an object which methods are safe to use for
350 : * example in nsIFrame code.
351 : */
352 4 : const nsFrameSelection* ConstFrameSelection() const { return mSelection; }
353 :
354 : // Make shell be a document observer. If called after Destroy() has
355 : // been called on the shell, this will be ignored.
356 : virtual void BeginObservingDocument() = 0;
357 :
358 : // Make shell stop being a document observer
359 : virtual void EndObservingDocument() = 0;
360 :
361 : /**
362 : * Return whether Initialize() was previously called.
363 : */
364 446 : bool DidInitialize() const { return mDidInitialize; }
365 :
366 : /**
367 : * Perform initialization. Constructs the frame for the root content
368 : * object and then enqueues a reflow of the frame model into the
369 : * specified width and height.
370 : *
371 : * The coordinates for aWidth and aHeight must be in standard nscoords.
372 : *
373 : * Callers of this method must hold a reference to this shell that
374 : * is guaranteed to survive through arbitrary script execution.
375 : * Calling Initialize can execute arbitrary script.
376 : */
377 : virtual nsresult Initialize(nscoord aWidth, nscoord aHeight) = 0;
378 :
379 : /**
380 : * Reflow the frame model into a new width and height. The
381 : * coordinates for aWidth and aHeight must be in standard nscoord's.
382 : */
383 : virtual nsresult ResizeReflow(nscoord aWidth, nscoord aHeight, nscoord aOldWidth = 0, nscoord aOldHeight = 0) = 0;
384 : /**
385 : * Do the same thing as ResizeReflow but even if ResizeReflowOverride was
386 : * called previously.
387 : */
388 : virtual nsresult ResizeReflowIgnoreOverride(nscoord aWidth, nscoord aHeight, nscoord aOldWidth, nscoord aOldHeight) = 0;
389 :
390 : /**
391 : * Returns true if ResizeReflowOverride has been called.
392 : */
393 : virtual bool GetIsViewportOverridden() = 0;
394 :
395 : /**
396 : * Return true if the presshell expects layout flush.
397 : */
398 : virtual bool IsLayoutFlushObserver() = 0;
399 :
400 : /**
401 : * Called when document load completes.
402 : */
403 : virtual void LoadComplete() = 0;
404 :
405 : /**
406 : * This calls through to the frame manager to get the root frame.
407 : */
408 : virtual nsIFrame* GetRootFrameExternal() const;
409 513 : nsIFrame* GetRootFrame() const {
410 : #ifdef MOZILLA_INTERNAL_API
411 513 : return mFrameManager->GetRootFrame();
412 : #else
413 : return GetRootFrameExternal();
414 : #endif
415 : }
416 :
417 : /*
418 : * Get root scroll frame from FrameManager()->GetRootFrame().
419 : */
420 : nsIFrame* GetRootScrollFrame() const;
421 :
422 : /*
423 : * The same as GetRootScrollFrame, but returns an nsIScrollableFrame
424 : */
425 : nsIScrollableFrame* GetRootScrollFrameAsScrollable() const;
426 :
427 : /*
428 : * The same as GetRootScrollFrame, but returns an nsIScrollableFrame.
429 : * Can be called by code not linked into gklayout.
430 : */
431 : virtual nsIScrollableFrame* GetRootScrollFrameAsScrollableExternal() const;
432 :
433 : /**
434 : * Get the current focused content or DOM selection that should be the
435 : * target for scrolling.
436 : */
437 : already_AddRefed<nsIContent> GetContentForScrolling() const;
438 :
439 : /**
440 : * Gets nearest scrollable frame from the specified content node. The frame
441 : * is scrollable with overflow:scroll or overflow:auto in some direction when
442 : * aDirection is eEither. Otherwise, this returns a nearest frame that is
443 : * scrollable in the specified direction.
444 : */
445 : enum ScrollDirection { eHorizontal, eVertical, eEither };
446 : nsIScrollableFrame* GetScrollableFrameToScrollForContent(
447 : nsIContent* aContent,
448 : ScrollDirection aDirection);
449 :
450 : /**
451 : * Gets nearest scrollable frame from current focused content or DOM
452 : * selection if there is no focused content. The frame is scrollable with
453 : * overflow:scroll or overflow:auto in some direction when aDirection is
454 : * eEither. Otherwise, this returns a nearest frame that is scrollable in
455 : * the specified direction.
456 : */
457 : nsIScrollableFrame* GetScrollableFrameToScroll(ScrollDirection aDirection);
458 :
459 : /**
460 : * Returns the page sequence frame associated with the frame hierarchy.
461 : * Returns nullptr if not a paginated view.
462 : */
463 : virtual nsIPageSequenceFrame* GetPageSequenceFrame() const = 0;
464 :
465 : /**
466 : * Returns the canvas frame associated with the frame hierarchy.
467 : * Returns nullptr if is XUL document.
468 : */
469 : virtual nsCanvasFrame* GetCanvasFrame() const = 0;
470 :
471 : /**
472 : * Tell the pres shell that a frame needs to be marked dirty and needs
473 : * Reflow. It's OK if this is an ancestor of the frame needing reflow as
474 : * long as the ancestor chain between them doesn't cross a reflow root.
475 : *
476 : * The bit to add should be NS_FRAME_IS_DIRTY, NS_FRAME_HAS_DIRTY_CHILDREN
477 : * or nsFrameState(0); passing 0 means that dirty bits won't be set on the
478 : * frame or its ancestors/descendants, but that intrinsic widths will still
479 : * be marked dirty. Passing aIntrinsicDirty = eResize and aBitToAdd = 0
480 : * would result in no work being done, so don't do that.
481 : */
482 : enum IntrinsicDirty {
483 : // XXXldb eResize should be renamed
484 : eResize, // don't mark any intrinsic widths dirty
485 : eTreeChange, // mark intrinsic widths dirty on aFrame and its ancestors
486 : eStyleChange // Do eTreeChange, plus all of aFrame's descendants
487 : };
488 : enum ReflowRootHandling {
489 : ePositionOrSizeChange, // aFrame is changing position or size
490 : eNoPositionOrSizeChange, // ... NOT changing ...
491 : eInferFromBitToAdd // is changing iff (aBitToAdd == NS_FRAME_IS_DIRTY)
492 :
493 : // Note: With eStyleChange, these can also apply to out-of-flows
494 : // in addition to aFrame.
495 : };
496 : virtual void FrameNeedsReflow(nsIFrame *aFrame,
497 : IntrinsicDirty aIntrinsicDirty,
498 : nsFrameState aBitToAdd,
499 : ReflowRootHandling aRootHandling =
500 : eInferFromBitToAdd) = 0;
501 :
502 : /**
503 : * Calls FrameNeedsReflow on all fixed position children of the root frame.
504 : */
505 : virtual void MarkFixedFramesForReflow(IntrinsicDirty aIntrinsicDirty);
506 :
507 : /**
508 : * Tell the presshell that the given frame's reflow was interrupted. This
509 : * will mark as having dirty children a path from the given frame (inclusive)
510 : * to the nearest ancestor with a dirty subtree, or to the reflow root
511 : * currently being reflowed if no such ancestor exists (inclusive). This is
512 : * to be done immediately after reflow of the current reflow root completes.
513 : * This method must only be called during reflow, and the frame it's being
514 : * called on must be in the process of being reflowed when it's called. This
515 : * method doesn't mark any intrinsic widths dirty and doesn't add any bits
516 : * other than NS_FRAME_HAS_DIRTY_CHILDREN.
517 : */
518 : virtual void FrameNeedsToContinueReflow(nsIFrame *aFrame) = 0;
519 :
520 : virtual void CancelAllPendingReflows() = 0;
521 :
522 : virtual void NotifyCounterStylesAreDirty() = 0;
523 :
524 : /**
525 : * Destroy the frames for aContent. Note that this may destroy frames
526 : * for an ancestor instead - aDestroyedFramesFor contains the content node
527 : * where frames were actually destroyed (which should be used in the
528 : * CreateFramesFor call). The frame tree state will be captured before
529 : * the frames are destroyed in the frame constructor.
530 : */
531 : virtual void DestroyFramesFor(nsIContent* aContent,
532 : nsIContent** aDestroyedFramesFor) = 0;
533 : /**
534 : * Create new frames for aContent. It will use the last captured layout
535 : * history state captured in the frame constructor to restore the state
536 : * in the new frame tree.
537 : */
538 : virtual void CreateFramesFor(nsIContent* aContent) = 0;
539 :
540 : void PostRecreateFramesFor(mozilla::dom::Element* aElement);
541 : void RestyleForAnimation(mozilla::dom::Element* aElement,
542 : nsRestyleHint aHint);
543 :
544 : // ShadowRoot has APIs that can change styles so we only
545 : // want to restyle elements in the ShadowRoot and not the whole
546 : // document.
547 : virtual void RecordShadowStyleChange(mozilla::dom::ShadowRoot* aShadowRoot) = 0;
548 :
549 : /**
550 : * Determine if it is safe to flush all pending notifications
551 : * @param aIsSafeToFlush true if it is safe, false otherwise.
552 : *
553 : */
554 : virtual bool IsSafeToFlush() const = 0;
555 :
556 : /**
557 : * Flush pending notifications of the type specified. This method
558 : * will not affect the content model; it'll just affect style and
559 : * frames. Callers that actually want up-to-date presentation (other
560 : * than the document itself) should probably be calling
561 : * nsIDocument::FlushPendingNotifications.
562 : *
563 : * This method can execute script, which can destroy this presshell object
564 : * unless someone is holding a reference to it on the stack. The presshell
565 : * itself will ensure it lives up until the method returns, but callers who
566 : * plan to use the presshell after this call should hold a strong ref
567 : * themselves!
568 : *
569 : * @param aType the type of notifications to flush
570 : */
571 : public:
572 106 : void FlushPendingNotifications(mozilla::FlushType aType)
573 : {
574 106 : if (!NeedFlush(aType)) {
575 39 : return;
576 : }
577 :
578 67 : DoFlushPendingNotifications(aType);
579 : }
580 :
581 141 : void FlushPendingNotifications(mozilla::ChangesToFlush aType)
582 : {
583 141 : if (!NeedFlush(aType.mFlushType)) {
584 19 : return;
585 : }
586 :
587 122 : DoFlushPendingNotifications(aType);
588 : }
589 :
590 : protected:
591 : /**
592 : * Implementation methods for FlushPendingNotifications.
593 : */
594 : virtual void DoFlushPendingNotifications(mozilla::FlushType aType) = 0;
595 : virtual void DoFlushPendingNotifications(mozilla::ChangesToFlush aType) = 0;
596 :
597 : public:
598 : /**
599 : * Whether we might need a flush for the given flush type. If this
600 : * function returns false, we definitely don't need to flush.
601 : *
602 : * @param aFlushType The flush type to check. This must be
603 : * >= FlushType::Style. This also returns true if a throttled
604 : * animation flush is required.
605 : */
606 369 : bool NeedFlush(mozilla::FlushType aType) const
607 : {
608 : // We check mInFlush to handle re-entrant calls to FlushPendingNotifications
609 : // by reporting that we always need a flush in that case. Otherwise,
610 : // we could end up missing needed flushes, since we clear the mNeedXXXFlush
611 : // flags at the top of FlushPendingNotifications.
612 369 : MOZ_ASSERT(aType >= mozilla::FlushType::Style);
613 555 : return mNeedStyleFlush ||
614 321 : (mNeedLayoutFlush &&
615 61 : aType >= mozilla::FlushType::InterruptibleLayout) ||
616 61 : aType >= mozilla::FlushType::Display ||
617 491 : mNeedThrottledAnimationFlush ||
618 430 : mInFlush;
619 : }
620 :
621 : inline void EnsureStyleFlush();
622 : inline void SetNeedStyleFlush();
623 : inline void SetNeedLayoutFlush();
624 : inline void SetNeedThrottledAnimationFlush();
625 :
626 253 : bool ObservingStyleFlushes() const { return mObservingStyleFlushes; }
627 342 : bool ObservingLayoutFlushes() const { return mObservingLayoutFlushes; }
628 :
629 215 : void ObserveStyleFlushes()
630 : {
631 215 : if (!ObservingStyleFlushes())
632 38 : DoObserveStyleFlushes();
633 215 : }
634 :
635 0 : bool NeedStyleFlush() const { return mNeedStyleFlush; }
636 :
637 : /**
638 : * Callbacks will be called even if reflow itself fails for
639 : * some reason.
640 : */
641 : virtual nsresult PostReflowCallback(nsIReflowCallback* aCallback) = 0;
642 : virtual void CancelReflowCallback(nsIReflowCallback* aCallback) = 0;
643 :
644 : virtual void ClearFrameRefs(nsIFrame* aFrame) = 0;
645 :
646 : /**
647 : * Get a reference rendering context. This is a context that should not
648 : * be rendered to, but is suitable for measuring text and performing
649 : * other non-rendering operations. Guaranteed to return non-null.
650 : */
651 : virtual already_AddRefed<gfxContext> CreateReferenceRenderingContext() = 0;
652 :
653 : /**
654 : * Informs the pres shell that the document is now at the anchor with
655 : * the given name. If |aScroll| is true, scrolls the view of the
656 : * document so that the anchor with the specified name is displayed at
657 : * the top of the window. If |aAnchorName| is empty, then this informs
658 : * the pres shell that there is no current target, and |aScroll| must
659 : * be false. If |aAdditionalScrollFlags| is nsIPresShell::SCROLL_SMOOTH_AUTO
660 : * and |aScroll| is true, the scrolling may be performed with an animation.
661 : */
662 : virtual nsresult GoToAnchor(const nsAString& aAnchorName, bool aScroll,
663 : uint32_t aAdditionalScrollFlags = 0) = 0;
664 :
665 : /**
666 : * Tells the presshell to scroll again to the last anchor scrolled to by
667 : * GoToAnchor, if any. This scroll only happens if the scroll
668 : * position has not changed since the last GoToAnchor. This is called
669 : * by nsDocumentViewer::LoadComplete. This clears the last anchor
670 : * scrolled to by GoToAnchor (we don't want to keep it alive if it's
671 : * removed from the DOM), so don't call this more than once.
672 : */
673 : virtual nsresult ScrollToAnchor() = 0;
674 :
675 : enum {
676 : SCROLL_TOP = 0,
677 : SCROLL_BOTTOM = 100,
678 : SCROLL_LEFT = 0,
679 : SCROLL_RIGHT = 100,
680 : SCROLL_CENTER = 50,
681 : SCROLL_MINIMUM = -1
682 : };
683 :
684 : enum WhenToScroll {
685 : SCROLL_ALWAYS,
686 : SCROLL_IF_NOT_VISIBLE,
687 : SCROLL_IF_NOT_FULLY_VISIBLE
688 : };
689 : typedef struct ScrollAxis {
690 : int16_t mWhereToScroll;
691 : WhenToScroll mWhenToScroll : 8;
692 : bool mOnlyIfPerceivedScrollableDirection : 1;
693 : /**
694 : * @param aWhere: Either a percentage or a special value.
695 : * nsIPresShell defines:
696 : * * (Default) SCROLL_MINIMUM = -1: The visible area is
697 : * scrolled to show the entire frame. If the frame is too
698 : * large, the top and left edges are given precedence.
699 : * * SCROLL_TOP = 0: The frame's upper edge is aligned with the
700 : * top edge of the visible area.
701 : * * SCROLL_BOTTOM = 100: The frame's bottom edge is aligned
702 : * with the bottom edge of the visible area.
703 : * * SCROLL_LEFT = 0: The frame's left edge is aligned with the
704 : * left edge of the visible area.
705 : * * SCROLL_RIGHT = 100: The frame's right edge is aligned with
706 : * the right edge of the visible area.
707 : * * SCROLL_CENTER = 50: The frame is centered along the axis
708 : * the ScrollAxis is used for.
709 : *
710 : * Other values are treated as a percentage, and the point
711 : * "percent" down the frame is placed at the point "percent"
712 : * down the visible area.
713 : * @param aWhen:
714 : * * (Default) SCROLL_IF_NOT_FULLY_VISIBLE: Move the frame only
715 : * if it is not fully visible (including if it's not visible
716 : * at all). Note that in this case if the frame is too large to
717 : * fit in view, it will only be scrolled if more of it can fit
718 : * than is already in view.
719 : * * SCROLL_IF_NOT_VISIBLE: Move the frame only if none of it
720 : * is visible.
721 : * * SCROLL_ALWAYS: Move the frame regardless of its current
722 : * visibility.
723 : * @param aOnlyIfPerceivedScrollableDirection:
724 : * If the direction is not a perceived scrollable direction (i.e.
725 : * no scrollbar showing and less than one device pixel of
726 : * scrollable distance), don't scroll. Defaults to false.
727 : */
728 10 : explicit ScrollAxis(int16_t aWhere = SCROLL_MINIMUM,
729 : WhenToScroll aWhen = SCROLL_IF_NOT_FULLY_VISIBLE,
730 10 : bool aOnlyIfPerceivedScrollableDirection = false) :
731 : mWhereToScroll(aWhere), mWhenToScroll(aWhen),
732 10 : mOnlyIfPerceivedScrollableDirection(aOnlyIfPerceivedScrollableDirection)
733 10 : {}
734 : } ScrollAxis;
735 : /**
736 : * Scrolls the view of the document so that the primary frame of the content
737 : * is displayed in the window. Layout is flushed before scrolling.
738 : *
739 : * @param aContent The content object of which primary frame should be
740 : * scrolled into view.
741 : * @param aVertical How to align the frame vertically and when to do so.
742 : * This is a ScrollAxis of Where and When.
743 : * @param aHorizontal How to align the frame horizontally and when to do so.
744 : * This is a ScrollAxis of Where and When.
745 : * @param aFlags If SCROLL_FIRST_ANCESTOR_ONLY is set, only the nearest
746 : * scrollable ancestor is scrolled, otherwise all
747 : * scrollable ancestors may be scrolled if necessary.
748 : * If SCROLL_OVERFLOW_HIDDEN is set then we may scroll in a
749 : * direction even if overflow:hidden is specified in that
750 : * direction; otherwise we will not scroll in that direction
751 : * when overflow:hidden is set for that direction.
752 : * If SCROLL_NO_PARENT_FRAMES is set then we only scroll
753 : * nodes in this document, not in any parent documents which
754 : * contain this document in a iframe or the like.
755 : * If SCROLL_SMOOTH is set and CSSOM-VIEW scroll-behavior
756 : * is enabled, we will scroll smoothly using
757 : * nsIScrollableFrame::ScrollMode::SMOOTH_MSD; otherwise,
758 : * nsIScrollableFrame::ScrollMode::INSTANT will be used.
759 : * If SCROLL_SMOOTH_AUTO is set, the CSSOM-View
760 : * scroll-behavior attribute is set to 'smooth' on the
761 : * scroll frame, and CSSOM-VIEW scroll-behavior is enabled,
762 : * we will scroll smoothly using
763 : * nsIScrollableFrame::ScrollMode::SMOOTH_MSD; otherwise,
764 : * nsIScrollableFrame::ScrollMode::INSTANT will be used.
765 : */
766 : virtual nsresult ScrollContentIntoView(nsIContent* aContent,
767 : ScrollAxis aVertical,
768 : ScrollAxis aHorizontal,
769 : uint32_t aFlags) = 0;
770 :
771 : enum {
772 : SCROLL_FIRST_ANCESTOR_ONLY = 0x01,
773 : SCROLL_OVERFLOW_HIDDEN = 0x02,
774 : SCROLL_NO_PARENT_FRAMES = 0x04,
775 : SCROLL_SMOOTH = 0x08,
776 : SCROLL_SMOOTH_AUTO = 0x10
777 : };
778 : /**
779 : * Scrolls the view of the document so that the given area of a frame
780 : * is visible, if possible. Layout is not flushed before scrolling.
781 : *
782 : * @param aRect relative to aFrame
783 : * @param aVertical see ScrollContentIntoView and ScrollAxis
784 : * @param aHorizontal see ScrollContentIntoView and ScrollAxis
785 : * @param aFlags if SCROLL_FIRST_ANCESTOR_ONLY is set, only the
786 : * nearest scrollable ancestor is scrolled, otherwise all
787 : * scrollable ancestors may be scrolled if necessary
788 : * if SCROLL_OVERFLOW_HIDDEN is set then we may scroll in a direction
789 : * even if overflow:hidden is specified in that direction; otherwise
790 : * we will not scroll in that direction when overflow:hidden is
791 : * set for that direction
792 : * If SCROLL_NO_PARENT_FRAMES is set then we only scroll
793 : * nodes in this document, not in any parent documents which
794 : * contain this document in a iframe or the like.
795 : * @return true if any scrolling happened, false if no scrolling happened
796 : */
797 : virtual bool ScrollFrameRectIntoView(nsIFrame* aFrame,
798 : const nsRect& aRect,
799 : ScrollAxis aVertical,
800 : ScrollAxis aHorizontal,
801 : uint32_t aFlags) = 0;
802 :
803 : /**
804 : * Determine if a rectangle specified in the frame's coordinate system
805 : * intersects the viewport "enough" to be considered visible.
806 : * @param aFrame frame that aRect coordinates are specified relative to
807 : * @param aRect rectangle in twips to test for visibility
808 : * @param aMinTwips is the minimum distance in from the edge of the viewport
809 : * that an object must be to be counted visible
810 : * @return nsRectVisibility_kVisible if the rect is visible
811 : * nsRectVisibility_kAboveViewport
812 : * nsRectVisibility_kBelowViewport
813 : * nsRectVisibility_kLeftOfViewport
814 : * nsRectVisibility_kRightOfViewport rectangle is outside the viewport
815 : * in the specified direction
816 : */
817 : virtual nsRectVisibility GetRectVisibility(nsIFrame *aFrame,
818 : const nsRect &aRect,
819 : nscoord aMinTwips) const = 0;
820 :
821 : /**
822 : * Suppress notification of the frame manager that frames are
823 : * being destroyed.
824 : */
825 : virtual void SetIgnoreFrameDestruction(bool aIgnore) = 0;
826 :
827 : /**
828 : * Notification sent by a frame informing the pres shell that it is about to
829 : * be destroyed.
830 : * This allows any outstanding references to the frame to be cleaned up
831 : */
832 : virtual void NotifyDestroyingFrame(nsIFrame* aFrame) = 0;
833 :
834 : /**
835 : * Get the AccessibleCaretEventHub, if it exists. AddRefs it.
836 : */
837 : virtual already_AddRefed<mozilla::AccessibleCaretEventHub> GetAccessibleCaretEventHub() const = 0;
838 :
839 : /**
840 : * Get the caret, if it exists. AddRefs it.
841 : */
842 : virtual already_AddRefed<nsCaret> GetCaret() const = 0;
843 :
844 : /**
845 : * Set the current caret to a new caret. To undo this, call RestoreCaret.
846 : */
847 : virtual void SetCaret(nsCaret *aNewCaret) = 0;
848 :
849 : /**
850 : * Restore the caret to the original caret that this pres shell was created
851 : * with.
852 : */
853 : virtual void RestoreCaret() = 0;
854 :
855 : /**
856 : * Should the images have borders etc. Actual visual effects are determined
857 : * by the frames. Visual effects may not effect layout, only display.
858 : * Takes effect on next repaint, does not force a repaint itself.
859 : *
860 : * @param aInEnable if true, visual selection effects are enabled
861 : * if false visual selection effects are disabled
862 : */
863 : NS_IMETHOD SetSelectionFlags(int16_t aInEnable) = 0;
864 :
865 : /**
866 : * Gets the current state of non text selection effects
867 : * @return current state of non text selection,
868 : * as set by SetDisplayNonTextSelection
869 : */
870 0 : int16_t GetSelectionFlags() const { return mSelectionFlags; }
871 :
872 : virtual mozilla::dom::Selection*
873 : GetCurrentSelection(mozilla::SelectionType aSelectionType) = 0;
874 :
875 : /**
876 : * Gets a selection controller for the focused content in the DOM window
877 : * for mDocument.
878 : *
879 : * @param aFocusedContent If there is focused content in the DOM window,
880 : * the focused content will be returned. This may
881 : * be nullptr if it's not necessary.
882 : * @return A selection controller for focused content.
883 : * E.g., if an <input> element has focus, returns
884 : * the independent selection controller of it.
885 : * If the DOM window does not have focused content
886 : * (similar to Document.activeElement), returns
887 : * nullptr.
888 : */
889 : virtual already_AddRefed<nsISelectionController>
890 : GetSelectionControllerForFocusedContent(
891 : nsIContent** aFocusedContent = nullptr) = 0;
892 :
893 : /**
894 : * Interface to dispatch events via the presshell
895 : * @note The caller must have a strong reference to the PresShell.
896 : */
897 : virtual nsresult HandleEventWithTarget(
898 : mozilla::WidgetEvent* aEvent,
899 : nsIFrame* aFrame,
900 : nsIContent* aContent,
901 : nsEventStatus* aStatus) = 0;
902 :
903 : /**
904 : * Dispatch event to content only (NOT full processing)
905 : * @note The caller must have a strong reference to the PresShell.
906 : */
907 : virtual nsresult HandleDOMEventWithTarget(
908 : nsIContent* aTargetContent,
909 : mozilla::WidgetEvent* aEvent,
910 : nsEventStatus* aStatus) = 0;
911 :
912 : /**
913 : * Dispatch event to content only (NOT full processing)
914 : * @note The caller must have a strong reference to the PresShell.
915 : */
916 : virtual nsresult HandleDOMEventWithTarget(nsIContent* aTargetContent,
917 : nsIDOMEvent* aEvent,
918 : nsEventStatus* aStatus) = 0;
919 :
920 : /**
921 : * Return whether or not the event is valid to be dispatched
922 : */
923 : virtual bool CanDispatchEvent(
924 : const mozilla::WidgetGUIEvent* aEvent = nullptr) const = 0;
925 :
926 : /**
927 : * Gets the current target event frame from the PresShell
928 : */
929 : virtual nsIFrame* GetEventTargetFrame() = 0;
930 :
931 : /**
932 : * Gets the current target event frame from the PresShell
933 : */
934 : virtual already_AddRefed<nsIContent> GetEventTargetContent(
935 : mozilla::WidgetEvent* aEvent) = 0;
936 :
937 : /**
938 : * Get and set the history state for the current document
939 : */
940 :
941 : virtual nsresult CaptureHistoryState(nsILayoutHistoryState** aLayoutHistoryState) = 0;
942 :
943 : /**
944 : * Determine if reflow is currently locked
945 : * returns true if reflow is locked, false otherwise
946 : */
947 2 : bool IsReflowLocked() const { return mIsReflowing; }
948 :
949 : /**
950 : * Called to find out if painting is suppressed for this presshell. If it is suppressd,
951 : * we don't allow the painting of any layer but the background, and we don't
952 : * recur into our children.
953 : */
954 125 : bool IsPaintingSuppressed() const { return mPaintingSuppressed; }
955 :
956 : /**
957 : * Pause painting by freezing the refresh driver of this and all parent
958 : * presentations. This may not have the desired effect if this pres shell
959 : * has its own refresh driver.
960 : */
961 : virtual void PausePainting() = 0;
962 :
963 : /**
964 : * Resume painting by thawing the refresh driver of this and all parent
965 : * presentations. This may not have the desired effect if this pres shell
966 : * has its own refresh driver.
967 : */
968 : virtual void ResumePainting() = 0;
969 :
970 : /**
971 : * Unsuppress painting.
972 : */
973 : virtual void UnsuppressPainting() = 0;
974 :
975 : /**
976 : * Get the set of agent style sheets for this presentation
977 : */
978 : virtual nsresult GetAgentStyleSheets(
979 : nsTArray<RefPtr<mozilla::StyleSheet>>& aSheets) = 0;
980 :
981 : /**
982 : * Replace the set of agent style sheets
983 : */
984 : virtual nsresult SetAgentStyleSheets(
985 : const nsTArray<RefPtr<mozilla::StyleSheet>>& aSheets) = 0;
986 :
987 : /**
988 : * Add an override style sheet for this presentation
989 : */
990 : virtual nsresult AddOverrideStyleSheet(mozilla::StyleSheet* aSheet) = 0;
991 :
992 : /**
993 : * Remove an override style sheet
994 : */
995 : virtual nsresult RemoveOverrideStyleSheet(mozilla::StyleSheet* aSheet) = 0;
996 :
997 : /**
998 : * Reconstruct frames for all elements in the document
999 : */
1000 : virtual void ReconstructFrames() = 0;
1001 :
1002 : /**
1003 : * Notify that a content node's state has changed
1004 : */
1005 : virtual void ContentStateChanged(nsIDocument* aDocument,
1006 : nsIContent* aContent,
1007 : mozilla::EventStates aStateMask) = 0;
1008 :
1009 : /**
1010 : * See if reflow verification is enabled. To enable reflow verification add
1011 : * "verifyreflow:1" to your MOZ_LOG environment variable (any non-zero
1012 : * debug level will work). Or, call SetVerifyReflowEnable with true.
1013 : */
1014 : static bool GetVerifyReflowEnable();
1015 :
1016 : /**
1017 : * Set the verify-reflow enable flag.
1018 : */
1019 : static void SetVerifyReflowEnable(bool aEnabled);
1020 :
1021 : virtual nsIFrame* GetAbsoluteContainingBlock(nsIFrame* aFrame);
1022 :
1023 : #ifdef MOZ_REFLOW_PERF
1024 : virtual void DumpReflows() = 0;
1025 : virtual void CountReflows(const char * aName, nsIFrame * aFrame) = 0;
1026 : virtual void PaintCount(const char * aName,
1027 : gfxContext* aRenderingContext,
1028 : nsPresContext * aPresContext,
1029 : nsIFrame * aFrame,
1030 : const nsPoint& aOffset,
1031 : uint32_t aColor) = 0;
1032 : virtual void SetPaintFrameCount(bool aOn) = 0;
1033 : virtual bool IsPaintingFrameCounts() = 0;
1034 : #endif
1035 :
1036 : #ifdef DEBUG
1037 : // Debugging hooks
1038 : virtual void ListStyleContexts(FILE *out, int32_t aIndent = 0) = 0;
1039 :
1040 : virtual void ListStyleSheets(FILE *out, int32_t aIndent = 0) = 0;
1041 : virtual void VerifyStyleTree() = 0;
1042 : #endif
1043 :
1044 : #ifdef ACCESSIBILITY
1045 : /**
1046 : * Return true if accessibility is active.
1047 : */
1048 : static bool IsAccessibilityActive();
1049 :
1050 : /**
1051 : * Return accessibility service if accessibility is active.
1052 : */
1053 : static nsAccessibilityService* AccService();
1054 : #endif
1055 :
1056 : /**
1057 : * Stop all active elements (plugins and the caret) in this presentation and
1058 : * in the presentations of subdocuments. Resets painting to a suppressed state.
1059 : * XXX this should include image animations
1060 : */
1061 : virtual void Freeze() = 0;
1062 : bool IsFrozen() { return mFrozen; }
1063 :
1064 : /**
1065 : * Restarts active elements (plugins) in this presentation and in the
1066 : * presentations of subdocuments, then do a full invalidate of the content area.
1067 : */
1068 : virtual void Thaw() = 0;
1069 :
1070 : virtual void FireOrClearDelayedEvents(bool aFireEvents) = 0;
1071 :
1072 : /**
1073 : * When this shell is disconnected from its containing docshell, we
1074 : * lose our container pointer. However, we'd still like to be able to target
1075 : * user events at the docshell's parent. This pointer allows us to do that.
1076 : * It should not be used for any other purpose.
1077 : */
1078 : void SetForwardingContainer(const mozilla::WeakPtr<nsDocShell> &aContainer);
1079 :
1080 : /**
1081 : * Render the document into an arbitrary gfxContext
1082 : * Designed for getting a picture of a document or a piece of a document
1083 : * Note that callers will generally want to call FlushPendingNotifications
1084 : * to get an up-to-date view of the document
1085 : * @param aRect is the region to capture into the offscreen buffer, in the
1086 : * root frame's coordinate system (if aIgnoreViewportScrolling is false)
1087 : * or in the root scrolled frame's coordinate system
1088 : * (if aIgnoreViewportScrolling is true). The coordinates are in appunits.
1089 : * @param aFlags see below;
1090 : * set RENDER_IS_UNTRUSTED if the contents may be passed to malicious
1091 : * agents. E.g. we might choose not to paint the contents of sensitive widgets
1092 : * such as the file name in a file upload widget, and we might choose not
1093 : * to paint themes.
1094 : * set RENDER_IGNORE_VIEWPORT_SCROLLING to ignore
1095 : * clipping and scrollbar painting due to scrolling in the viewport
1096 : * set RENDER_CARET to draw the caret if one would be visible
1097 : * (by default the caret is never drawn)
1098 : * set RENDER_USE_LAYER_MANAGER to force rendering to go through
1099 : * the layer manager for the window. This may be unexpectedly slow
1100 : * (if the layer manager must read back data from the GPU) or low-quality
1101 : * (if the layer manager reads back pixel data and scales it
1102 : * instead of rendering using the appropriate scaling). It may also
1103 : * slow everything down if the area rendered does not correspond to the
1104 : * normal visible area of the window.
1105 : * set RENDER_ASYNC_DECODE_IMAGES to avoid having images synchronously
1106 : * decoded during rendering.
1107 : * (by default images decode synchronously with RenderDocument)
1108 : * set RENDER_DOCUMENT_RELATIVE to render the document as if there has been
1109 : * no scrolling and interpret |aRect| relative to the document instead of the
1110 : * CSS viewport. Only considered if RENDER_IGNORE_VIEWPORT_SCROLLING is set
1111 : * or the document is in ignore viewport scrolling mode
1112 : * (nsIPresShell::SetIgnoreViewportScrolling/IgnoringViewportScrolling).
1113 : * @param aBackgroundColor a background color to render onto
1114 : * @param aRenderedContext the gfxContext to render to. We render so that
1115 : * one CSS pixel in the source document is rendered to one unit in the current
1116 : * transform.
1117 : */
1118 : enum {
1119 : RENDER_IS_UNTRUSTED = 0x01,
1120 : RENDER_IGNORE_VIEWPORT_SCROLLING = 0x02,
1121 : RENDER_CARET = 0x04,
1122 : RENDER_USE_WIDGET_LAYERS = 0x08,
1123 : RENDER_ASYNC_DECODE_IMAGES = 0x10,
1124 : RENDER_DOCUMENT_RELATIVE = 0x20,
1125 : RENDER_DRAWWINDOW_NOT_FLUSHING = 0x40
1126 : };
1127 : virtual nsresult RenderDocument(const nsRect& aRect, uint32_t aFlags,
1128 : nscolor aBackgroundColor,
1129 : gfxContext* aRenderedContext) = 0;
1130 :
1131 : enum {
1132 : RENDER_IS_IMAGE = 0x100,
1133 : RENDER_AUTO_SCALE = 0x80
1134 : };
1135 :
1136 : /**
1137 : * Renders a node aNode to a surface and returns it. The aRegion may be used
1138 : * to clip the rendering. This region is measured in CSS pixels from the
1139 : * edge of the presshell area. The aPoint, aScreenRect and aFlags arguments
1140 : * function in a similar manner as RenderSelection.
1141 : */
1142 : virtual already_AddRefed<mozilla::gfx::SourceSurface>
1143 : RenderNode(nsIDOMNode* aNode,
1144 : nsIntRegion* aRegion,
1145 : const mozilla::LayoutDeviceIntPoint aPoint,
1146 : mozilla::LayoutDeviceIntRect* aScreenRect,
1147 : uint32_t aFlags) = 0;
1148 :
1149 : /**
1150 : * Renders a selection to a surface and returns it. This method is primarily
1151 : * intended to create the drag feedback when dragging a selection.
1152 : *
1153 : * aScreenRect will be filled in with the bounding rectangle of the
1154 : * selection area on screen.
1155 : *
1156 : * If the area of the selection is large and the RENDER_AUTO_SCALE flag is
1157 : * set, the image will be scaled down. The argument aPoint is used in this
1158 : * case as a reference point when determining the new screen rectangle after
1159 : * scaling. Typically, this will be the mouse position, so that the screen
1160 : * rectangle is positioned such that the mouse is over the same point in the
1161 : * scaled image as in the original. When scaling does not occur, the mouse
1162 : * point isn't used because the position can be determined from the displayed
1163 : * frames.
1164 : */
1165 : virtual already_AddRefed<mozilla::gfx::SourceSurface>
1166 : RenderSelection(nsISelection* aSelection,
1167 : const mozilla::LayoutDeviceIntPoint aPoint,
1168 : mozilla::LayoutDeviceIntRect* aScreenRect,
1169 : uint32_t aFlags) = 0;
1170 :
1171 : void AddAutoWeakFrameInternal(AutoWeakFrame* aWeakFrame);
1172 : virtual void AddAutoWeakFrameExternal(AutoWeakFrame* aWeakFrame);
1173 : void AddWeakFrameInternal(WeakFrame* aWeakFrame);
1174 : virtual void AddWeakFrameExternal(WeakFrame* aWeakFrame);
1175 :
1176 118 : void AddAutoWeakFrame(AutoWeakFrame* aWeakFrame)
1177 : {
1178 : #ifdef MOZILLA_INTERNAL_API
1179 118 : AddAutoWeakFrameInternal(aWeakFrame);
1180 : #else
1181 : AddAutoWeakFrameExternal(aWeakFrame);
1182 : #endif
1183 118 : }
1184 41 : void AddWeakFrame(WeakFrame* aWeakFrame)
1185 : {
1186 : #ifdef MOZILLA_INTERNAL_API
1187 41 : AddWeakFrameInternal(aWeakFrame);
1188 : #else
1189 : AddWeakFrameExternal(aWeakFrame);
1190 : #endif
1191 41 : }
1192 :
1193 : void RemoveAutoWeakFrameInternal(AutoWeakFrame* aWeakFrame);
1194 : virtual void RemoveAutoWeakFrameExternal(AutoWeakFrame* aWeakFrame);
1195 : void RemoveWeakFrameInternal(WeakFrame* aWeakFrame);
1196 : virtual void RemoveWeakFrameExternal(WeakFrame* aWeakFrame);
1197 :
1198 118 : void RemoveAutoWeakFrame(AutoWeakFrame* aWeakFrame)
1199 : {
1200 : #ifdef MOZILLA_INTERNAL_API
1201 118 : RemoveAutoWeakFrameInternal(aWeakFrame);
1202 : #else
1203 : RemoveAutoWeakFrameExternal(aWeakFrame);
1204 : #endif
1205 118 : }
1206 41 : void RemoveWeakFrame(WeakFrame* aWeakFrame)
1207 : {
1208 : #ifdef MOZILLA_INTERNAL_API
1209 41 : RemoveWeakFrameInternal(aWeakFrame);
1210 : #else
1211 : RemoveWeakFrameExternal(aWeakFrame);
1212 : #endif
1213 41 : }
1214 :
1215 : #ifdef DEBUG
1216 0 : nsIFrame* GetDrawEventTargetFrame() { return mDrawEventTargetFrame; }
1217 : #endif
1218 :
1219 : /**
1220 : * Stop or restart non synthetic test mouse event handling on *all*
1221 : * presShells.
1222 : *
1223 : * @param aDisable If true, disable all non synthetic test mouse
1224 : * events on all presShells. Otherwise, enable them.
1225 : */
1226 : virtual void DisableNonTestMouseEvents(bool aDisable) = 0;
1227 :
1228 : /**
1229 : * Record the background color of the most recently drawn canvas. This color
1230 : * is composited on top of the user's default background color and then used
1231 : * to draw the background color of the canvas. See PresShell::Paint,
1232 : * PresShell::PaintDefaultBackground, and nsDocShell::SetupNewViewer;
1233 : * bug 488242, bug 476557 and other bugs mentioned there.
1234 : */
1235 7 : void SetCanvasBackground(nscolor aColor) { mCanvasBackgroundColor = aColor; }
1236 6 : nscolor GetCanvasBackground() { return mCanvasBackgroundColor; }
1237 :
1238 : /**
1239 : * Use the current frame tree (if it exists) to update the background
1240 : * color of the most recently drawn canvas.
1241 : */
1242 : virtual void UpdateCanvasBackground() = 0;
1243 :
1244 : /**
1245 : * Add a solid color item to the bottom of aList with frame aFrame and bounds
1246 : * aBounds. Checks first if this needs to be done by checking if aFrame is a
1247 : * canvas frame (if the FORCE_DRAW flag is passed then this check is skipped).
1248 : * aBackstopColor is composed behind the background color of the canvas, it is
1249 : * transparent by default.
1250 : * We attempt to make the background color part of the scrolled canvas (to reduce
1251 : * transparent layers), and if async scrolling is enabled (and the background
1252 : * is opaque) then we add a second, unscrolled item to handle the checkerboarding
1253 : * case.
1254 : * ADD_FOR_SUBDOC shoud be specified when calling this for a subdocument, and
1255 : * LayoutUseContainersForRootFrame might cause the whole list to be scrolled. In
1256 : * that case the second unscrolled item will be elided.
1257 : * APPEND_UNSCROLLED_ONLY only attempts to add the unscrolled item, so that we
1258 : * can add it manually after LayoutUseContainersForRootFrame has built the
1259 : * scrolling ContainerLayer.
1260 : */
1261 : enum {
1262 : FORCE_DRAW = 0x01,
1263 : ADD_FOR_SUBDOC = 0x02,
1264 : APPEND_UNSCROLLED_ONLY = 0x04,
1265 : };
1266 : virtual void AddCanvasBackgroundColorItem(nsDisplayListBuilder& aBuilder,
1267 : nsDisplayList& aList,
1268 : nsIFrame* aFrame,
1269 : const nsRect& aBounds,
1270 : nscolor aBackstopColor = NS_RGBA(0,0,0,0),
1271 : uint32_t aFlags = 0) = 0;
1272 :
1273 :
1274 : /**
1275 : * Add a solid color item to the bottom of aList with frame aFrame and
1276 : * bounds aBounds representing the dark grey background behind the page of a
1277 : * print preview presentation.
1278 : */
1279 : virtual void AddPrintPreviewBackgroundItem(nsDisplayListBuilder& aBuilder,
1280 : nsDisplayList& aList,
1281 : nsIFrame* aFrame,
1282 : const nsRect& aBounds) = 0;
1283 :
1284 : /**
1285 : * Computes the backstop color for the view: transparent if in a transparent
1286 : * widget, otherwise the PresContext default background color. This color is
1287 : * only visible if the contents of the view as a whole are translucent.
1288 : */
1289 : virtual nscolor ComputeBackstopColor(nsView* aDisplayRoot) = 0;
1290 :
1291 0 : void ObserveNativeAnonMutationsForPrint(bool aObserve)
1292 : {
1293 0 : mObservesMutationsForPrint = aObserve;
1294 0 : }
1295 0 : bool ObservesNativeAnonMutationsForPrint()
1296 : {
1297 0 : return mObservesMutationsForPrint;
1298 : }
1299 :
1300 : virtual nsresult SetIsActive(bool aIsActive) = 0;
1301 :
1302 4 : bool IsActive()
1303 : {
1304 4 : return mIsActive;
1305 : }
1306 :
1307 : // mouse capturing
1308 : static CapturingContentInfo gCaptureInfo;
1309 :
1310 : class PointerCaptureInfo final
1311 : {
1312 : public:
1313 : nsCOMPtr<nsIContent> mPendingContent;
1314 : nsCOMPtr<nsIContent> mOverrideContent;
1315 :
1316 0 : explicit PointerCaptureInfo(nsIContent* aPendingContent)
1317 0 : : mPendingContent(aPendingContent)
1318 : {
1319 0 : MOZ_COUNT_CTOR(PointerCaptureInfo);
1320 0 : }
1321 :
1322 0 : ~PointerCaptureInfo()
1323 0 : {
1324 0 : MOZ_COUNT_DTOR(PointerCaptureInfo);
1325 0 : }
1326 :
1327 0 : bool Empty()
1328 : {
1329 0 : return !(mPendingContent || mOverrideContent);
1330 : }
1331 : };
1332 :
1333 : class PointerInfo final
1334 : {
1335 : public:
1336 : uint16_t mPointerType;
1337 : bool mActiveState;
1338 : bool mPrimaryState;
1339 : bool mPreventMouseEventByContent;
1340 1 : explicit PointerInfo(bool aActiveState, uint16_t aPointerType,
1341 : bool aPrimaryState)
1342 1 : : mPointerType(aPointerType)
1343 : , mActiveState(aActiveState)
1344 : , mPrimaryState(aPrimaryState)
1345 1 : , mPreventMouseEventByContent(false)
1346 : {
1347 1 : }
1348 : };
1349 :
1350 : static void DispatchGotOrLostPointerCaptureEvent(
1351 : bool aIsGotCapture,
1352 : const mozilla::WidgetPointerEvent* aPointerEvent,
1353 : nsIContent* aCaptureTarget);
1354 :
1355 : static PointerCaptureInfo* GetPointerCaptureInfo(uint32_t aPointerId);
1356 : static void SetPointerCapturingContent(uint32_t aPointerId,
1357 : nsIContent* aContent);
1358 : static void ReleasePointerCapturingContent(uint32_t aPointerId);
1359 : static nsIContent* GetPointerCapturingContent(uint32_t aPointerId);
1360 :
1361 : // CheckPointerCaptureState checks cases, when got/lostpointercapture events
1362 : // should be fired.
1363 : static void CheckPointerCaptureState(
1364 : const mozilla::WidgetPointerEvent* aPointerEvent);
1365 :
1366 : // GetPointerInfo returns true if pointer with aPointerId is situated in
1367 : // device, false otherwise.
1368 : // aActiveState is additional information, which shows state of pointer like
1369 : // button state for mouse.
1370 : static bool GetPointerInfo(uint32_t aPointerId, bool& aActiveState);
1371 :
1372 : // GetPointerType returns pointer type like mouse, pen or touch for pointer
1373 : // event with pointerId
1374 : static uint16_t GetPointerType(uint32_t aPointerId);
1375 :
1376 : // GetPointerPrimaryState returns state of attribute isPrimary for pointer
1377 : // event with pointerId
1378 : static bool GetPointerPrimaryState(uint32_t aPointerId);
1379 :
1380 : /**
1381 : * When capturing content is set, it traps all mouse events and retargets
1382 : * them at this content node. If capturing is not allowed
1383 : * (gCaptureInfo.mAllowed is false), then capturing is not set. However, if
1384 : * the CAPTURE_IGNOREALLOWED flag is set, the allowed state is ignored and
1385 : * capturing is set regardless. To disable capture, pass null for the value
1386 : * of aContent.
1387 : *
1388 : * If CAPTURE_RETARGETTOELEMENT is set, all mouse events are targeted at
1389 : * aContent only. Otherwise, mouse events are targeted at aContent or its
1390 : * descendants. That is, descendants of aContent receive mouse events as
1391 : * they normally would, but mouse events outside of aContent are retargeted
1392 : * to aContent.
1393 : *
1394 : * If CAPTURE_PREVENTDRAG is set then drags are prevented from starting while
1395 : * this capture is active.
1396 : *
1397 : * If CAPTURE_POINTERLOCK is set, similar to CAPTURE_RETARGETTOELEMENT, then
1398 : * events are targeted at aContent, but capturing is held more strongly (i.e.,
1399 : * calls to SetCapturingContent won't unlock unless CAPTURE_POINTERLOCK is
1400 : * set again).
1401 : */
1402 : static void SetCapturingContent(nsIContent* aContent, uint8_t aFlags);
1403 :
1404 : /**
1405 : * Return the active content currently capturing the mouse if any.
1406 : */
1407 10 : static nsIContent* GetCapturingContent()
1408 : {
1409 10 : return gCaptureInfo.mContent;
1410 : }
1411 :
1412 : /**
1413 : * Allow or disallow mouse capturing.
1414 : */
1415 8 : static void AllowMouseCapture(bool aAllowed)
1416 : {
1417 8 : gCaptureInfo.mAllowed = aAllowed;
1418 8 : }
1419 :
1420 : /**
1421 : * Returns true if there is an active mouse capture that wants to prevent
1422 : * drags.
1423 : */
1424 0 : static bool IsMouseCapturePreventingDrag()
1425 : {
1426 0 : return gCaptureInfo.mPreventDrag && gCaptureInfo.mContent;
1427 : }
1428 :
1429 : /**
1430 : * Keep track of how many times this presshell has been rendered to
1431 : * a window.
1432 : */
1433 0 : uint64_t GetPaintCount() { return mPaintCount; }
1434 27 : void IncrementPaintCount() { ++mPaintCount; }
1435 :
1436 : /**
1437 : * Get the root DOM window of this presShell.
1438 : */
1439 : virtual already_AddRefed<nsPIDOMWindowOuter> GetRootWindow() = 0;
1440 :
1441 : /**
1442 : * This returns the focused DOM window under our top level window.
1443 : * I.e., when we are deactive, this returns the *last* focused DOM window.
1444 : */
1445 : virtual already_AddRefed<nsPIDOMWindowOuter> GetFocusedDOMWindowInOurWindow() = 0;
1446 :
1447 : /**
1448 : * Get the layer manager for the widget of the root view, if it has
1449 : * one.
1450 : */
1451 : virtual LayerManager* GetLayerManager() = 0;
1452 :
1453 : /**
1454 : * Return true iff there is a widget rendering this presShell and that
1455 : * widget is APZ-enabled.
1456 : */
1457 : virtual bool AsyncPanZoomEnabled() = 0;
1458 :
1459 : /**
1460 : * Track whether we're ignoring viewport scrolling for the purposes
1461 : * of painting. If we are ignoring, then layers aren't clipped to
1462 : * the CSS viewport and scrollbars aren't drawn.
1463 : */
1464 : virtual void SetIgnoreViewportScrolling(bool aIgnore) = 0;
1465 3557 : bool IgnoringViewportScrolling() const
1466 3557 : { return mRenderFlags & STATE_IGNORING_VIEWPORT_SCROLLING; }
1467 :
1468 : /**
1469 : * Set a "resolution" for the document, which if not 1.0 will
1470 : * allocate more or fewer pixels for rescalable content by a factor
1471 : * of |resolution| in both dimensions. Return NS_OK iff the
1472 : * resolution bounds are sane, and the resolution of this was
1473 : * actually updated.
1474 : *
1475 : * The resolution defaults to 1.0.
1476 : */
1477 : virtual nsresult SetResolution(float aResolution) = 0;
1478 805 : float GetResolution() const { return mResolution.valueOr(1.0); }
1479 : virtual float GetCumulativeResolution() = 0;
1480 :
1481 : /**
1482 : * Calculate the cumulative scale resolution from this document up to
1483 : * but not including the root document.
1484 : */
1485 : virtual float GetCumulativeNonRootScaleResolution() = 0;
1486 :
1487 : /**
1488 : * Was the current resolution set by the user or just default initialized?
1489 : */
1490 0 : bool IsResolutionSet() { return mResolution.isSome(); }
1491 :
1492 : /**
1493 : * Similar to SetResolution() but also increases the scale of the content
1494 : * by the same amount.
1495 : */
1496 : virtual nsresult SetResolutionAndScaleTo(float aResolution) = 0;
1497 :
1498 : /**
1499 : * Return whether we are scaling to the set resolution.
1500 : * This is initially false; it's set to true by a call to
1501 : * SetResolutionAndScaleTo(), and set to false by a call to SetResolution().
1502 : */
1503 : virtual bool ScaleToResolution() const = 0;
1504 :
1505 : /**
1506 : * Used by session restore code to restore a resolution before the first
1507 : * paint.
1508 : */
1509 : virtual void SetRestoreResolution(float aResolution,
1510 : mozilla::LayoutDeviceIntSize aDisplaySize) = 0;
1511 :
1512 : /**
1513 : * Returns whether we are in a DrawWindow() call that used the
1514 : * DRAWWINDOW_DO_NOT_FLUSH flag.
1515 : */
1516 0 : bool InDrawWindowNotFlushing() const
1517 0 : { return mRenderFlags & STATE_DRAWWINDOW_NOT_FLUSHING; }
1518 :
1519 : /**
1520 : * Set the isFirstPaint flag.
1521 : */
1522 1 : void SetIsFirstPaint(bool aIsFirstPaint) { mIsFirstPaint = aIsFirstPaint; }
1523 :
1524 : /**
1525 : * Get the isFirstPaint flag.
1526 : */
1527 0 : bool GetIsFirstPaint() const { return mIsFirstPaint; }
1528 :
1529 30 : uint32_t GetPresShellId() { return mPresShellId; }
1530 :
1531 : /**
1532 : * Dispatch a mouse move event based on the most recent mouse position if
1533 : * this PresShell is visible. This is used when the contents of the page
1534 : * moved (aFromScroll is false) or scrolled (aFromScroll is true).
1535 : */
1536 : virtual void SynthesizeMouseMove(bool aFromScroll) = 0;
1537 :
1538 : enum PaintFlags {
1539 : /* Update the layer tree and paint PaintedLayers. If this is not specified,
1540 : * we may still have to do it if the layer tree lost PaintedLayer contents
1541 : * we need for compositing. */
1542 : PAINT_LAYERS = 0x01,
1543 : /* Composite layers to the window. */
1544 : PAINT_COMPOSITE = 0x02,
1545 : /* Sync-decode images. */
1546 : PAINT_SYNC_DECODE_IMAGES = 0x04
1547 : };
1548 : virtual void Paint(nsView* aViewToPaint, const nsRegion& aDirtyRegion,
1549 : uint32_t aFlags) = 0;
1550 : virtual nsresult HandleEvent(nsIFrame* aFrame,
1551 : mozilla::WidgetGUIEvent* aEvent,
1552 : bool aDontRetargetEvents,
1553 : nsEventStatus* aEventStatus,
1554 : nsIContent** aTargetContent = nullptr) = 0;
1555 : virtual bool ShouldIgnoreInvalidation() = 0;
1556 : /**
1557 : * Notify that we're going to call Paint with PAINT_LAYERS
1558 : * on the pres shell for a widget (which might not be this one, since
1559 : * WillPaint is called on all presshells in the same toplevel window as the
1560 : * painted widget). This is issued at a time when it's safe to modify
1561 : * widget geometry.
1562 : */
1563 : virtual void WillPaint() = 0;
1564 : /**
1565 : * Notify that we're going to call Paint with PAINT_COMPOSITE.
1566 : * Fires on the presshell for the painted widget.
1567 : * This is issued at a time when it's safe to modify widget geometry.
1568 : */
1569 : virtual void WillPaintWindow() = 0;
1570 : /**
1571 : * Notify that we called Paint with PAINT_COMPOSITE.
1572 : * Fires on the presshell for the painted widget.
1573 : * This is issued at a time when it's safe to modify widget geometry.
1574 : */
1575 : virtual void DidPaintWindow() = 0;
1576 :
1577 : /**
1578 : * Ensures that the refresh driver is running, and schedules a view
1579 : * manager flush on the next tick.
1580 : *
1581 : * @param aType PAINT_DELAYED_COMPRESS : Schedule a paint to be executed after a delay, and
1582 : * put FrameLayerBuilder in 'compressed' mode that avoids short cut optimizations.
1583 : */
1584 : enum PaintType {
1585 : PAINT_DEFAULT,
1586 : PAINT_DELAYED_COMPRESS
1587 : };
1588 : virtual void ScheduleViewManagerFlush(PaintType aType = PAINT_DEFAULT) = 0;
1589 : virtual void ClearMouseCaptureOnView(nsView* aView) = 0;
1590 : virtual bool IsVisible() = 0;
1591 : virtual void DispatchSynthMouseMove(mozilla::WidgetGUIEvent* aEvent,
1592 : bool aFlushOnHoverChange) = 0;
1593 :
1594 : virtual void AddSizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf,
1595 : nsArenaMemoryStats* aArenaObjectsSize,
1596 : size_t* aPresShellSize,
1597 : size_t* aStyleSetsSize,
1598 : size_t* aTextRunsSize,
1599 : size_t* aPresContextSize,
1600 : size_t* aFramePropertiesSize) = 0;
1601 :
1602 : /**
1603 : * Methods that retrieve the cached font inflation preferences.
1604 : */
1605 24 : uint32_t FontSizeInflationEmPerLine() const {
1606 24 : return mFontSizeInflationEmPerLine;
1607 : }
1608 :
1609 24 : uint32_t FontSizeInflationMinTwips() const {
1610 24 : return mFontSizeInflationMinTwips;
1611 : }
1612 :
1613 0 : uint32_t FontSizeInflationLineThreshold() const {
1614 0 : return mFontSizeInflationLineThreshold;
1615 : }
1616 :
1617 0 : bool FontSizeInflationForceEnabled() const {
1618 0 : return mFontSizeInflationForceEnabled;
1619 : }
1620 :
1621 0 : bool FontSizeInflationDisabledInMasterProcess() const {
1622 0 : return mFontSizeInflationDisabledInMasterProcess;
1623 : }
1624 :
1625 : /**
1626 : * Determine if font size inflation is enabled. This value is cached until
1627 : * it becomes dirty.
1628 : *
1629 : * @returns true, if font size inflation is enabled; false otherwise.
1630 : */
1631 : bool FontSizeInflationEnabled();
1632 :
1633 : /**
1634 : * Notify the pres shell that an event occurred making the current value of
1635 : * mFontSizeInflationEnabled invalid. This will schedule a recomputation of
1636 : * whether font size inflation is enabled on the next call to
1637 : * FontSizeInflationEnabled().
1638 : */
1639 28 : void NotifyFontSizeInflationEnabledIsDirty()
1640 : {
1641 28 : mFontSizeInflationEnabledIsDirty = true;
1642 28 : }
1643 :
1644 : //////////////////////////////////////////////////////////////////////////////
1645 : // Approximate frame visibility tracking public API.
1646 : //////////////////////////////////////////////////////////////////////////////
1647 :
1648 : /// Schedule an update of the list of approximately visible frames "soon".
1649 : /// This lets the refresh driver know that we want a visibility update in the
1650 : /// near future. The refresh driver applies its own heuristics and throttling
1651 : /// to decide when to actually perform the visibility update.
1652 : virtual void ScheduleApproximateFrameVisibilityUpdateSoon() = 0;
1653 :
1654 : /// Schedule an update of the list of approximately visible frames "now". The
1655 : /// update runs asynchronously, but it will be posted to the event loop
1656 : /// immediately. Prefer the "soon" variation of this method when possible, as
1657 : /// this variation ignores the refresh driver's heuristics.
1658 : virtual void ScheduleApproximateFrameVisibilityUpdateNow() = 0;
1659 :
1660 : /// Clears the current list of approximately visible frames on this pres shell
1661 : /// and replaces it with frames that are in the display list @aList.
1662 : virtual void RebuildApproximateFrameVisibilityDisplayList(const nsDisplayList& aList) = 0;
1663 : virtual void RebuildApproximateFrameVisibility(nsRect* aRect = nullptr,
1664 : bool aRemoveOnly = false) = 0;
1665 :
1666 : /// Ensures @aFrame is in the list of approximately visible frames.
1667 : virtual void EnsureFrameInApproximatelyVisibleList(nsIFrame* aFrame) = 0;
1668 :
1669 : /// Removes @aFrame from the list of approximately visible frames if present.
1670 : virtual void RemoveFrameFromApproximatelyVisibleList(nsIFrame* aFrame) = 0;
1671 :
1672 : /// Whether we should assume all frames are visible.
1673 : virtual bool AssumeAllFramesVisible() = 0;
1674 :
1675 :
1676 : /**
1677 : * Returns whether the document's style set's rule processor for the
1678 : * specified level of the cascade is shared by multiple style sets.
1679 : *
1680 : * @param aSheetType One of the nsIStyleSheetService.*_SHEET constants.
1681 : */
1682 : nsresult HasRuleProcessorUsedByMultipleStyleSets(uint32_t aSheetType,
1683 : bool* aRetVal);
1684 :
1685 : /**
1686 : * Refresh observer management.
1687 : */
1688 : protected:
1689 : virtual bool AddRefreshObserverExternal(nsARefreshObserver* aObserver,
1690 : mozilla::FlushType aFlushType);
1691 : bool AddRefreshObserverInternal(nsARefreshObserver* aObserver,
1692 : mozilla::FlushType aFlushType);
1693 : virtual bool RemoveRefreshObserverExternal(nsARefreshObserver* aObserver,
1694 : mozilla::FlushType aFlushType);
1695 : bool RemoveRefreshObserverInternal(nsARefreshObserver* aObserver,
1696 : mozilla::FlushType aFlushType);
1697 :
1698 : void DoObserveStyleFlushes();
1699 : void DoObserveLayoutFlushes();
1700 :
1701 : /**
1702 : * Do computations necessary to determine if font size inflation is enabled.
1703 : * This value is cached after computation, as the computation is somewhat
1704 : * expensive.
1705 : */
1706 : void RecomputeFontSizeInflationEnabled();
1707 :
1708 : /**
1709 : * Does the actual work of figuring out the current state of font size inflation.
1710 : */
1711 : bool DetermineFontSizeInflationState();
1712 :
1713 : /**
1714 : * Apply the system font scale from the corresponding pref to the PresContext,
1715 : * taking into account the current state of font size inflation.
1716 : */
1717 : void HandleSystemFontScale();
1718 :
1719 11959 : void RecordAlloc(void* aPtr) {
1720 : #ifdef DEBUG
1721 11959 : MOZ_ASSERT(!mAllocatedPointers.Contains(aPtr));
1722 11959 : mAllocatedPointers.PutEntry(aPtr);
1723 : #endif
1724 11959 : }
1725 :
1726 6856 : void RecordFree(void* aPtr) {
1727 : #ifdef DEBUG
1728 6856 : MOZ_ASSERT(mAllocatedPointers.Contains(aPtr));
1729 6856 : mAllocatedPointers.RemoveEntry(aPtr);
1730 : #endif
1731 6856 : }
1732 :
1733 : public:
1734 0 : bool AddRefreshObserver(nsARefreshObserver* aObserver,
1735 : mozilla::FlushType aFlushType) {
1736 : #ifdef MOZILLA_INTERNAL_API
1737 0 : return AddRefreshObserverInternal(aObserver, aFlushType);
1738 : #else
1739 : return AddRefreshObserverExternal(aObserver, aFlushType);
1740 : #endif
1741 : }
1742 :
1743 0 : bool RemoveRefreshObserver(nsARefreshObserver* aObserver,
1744 : mozilla::FlushType aFlushType) {
1745 : #ifdef MOZILLA_INTERNAL_API
1746 0 : return RemoveRefreshObserverInternal(aObserver, aFlushType);
1747 : #else
1748 : return RemoveRefreshObserverExternal(aObserver, aFlushType);
1749 : #endif
1750 : }
1751 :
1752 : virtual bool AddPostRefreshObserver(nsAPostRefreshObserver* aObserver);
1753 : virtual bool RemovePostRefreshObserver(nsAPostRefreshObserver* aObserver);
1754 :
1755 : /**
1756 : * Initialize and shut down static variables.
1757 : */
1758 : static void InitializeStatics();
1759 : static void ReleaseStatics();
1760 :
1761 : // If a frame in the subtree rooted at aFrame is capturing the mouse then
1762 : // clears that capture.
1763 : static void ClearMouseCapture(nsIFrame* aFrame);
1764 :
1765 : void SetScrollPositionClampingScrollPortSize(nscoord aWidth, nscoord aHeight);
1766 152 : bool IsScrollPositionClampingScrollPortSizeSet() {
1767 152 : return mScrollPositionClampingScrollPortSizeSet;
1768 : }
1769 0 : nsSize GetScrollPositionClampingScrollPortSize() {
1770 0 : NS_ASSERTION(mScrollPositionClampingScrollPortSizeSet, "asking for scroll port when its not set?");
1771 0 : return mScrollPositionClampingScrollPortSize;
1772 : }
1773 :
1774 : virtual void WindowSizeMoveDone() = 0;
1775 : virtual void SysColorChanged() = 0;
1776 : virtual void ThemeChanged() = 0;
1777 : virtual void BackingScaleFactorChanged() = 0;
1778 :
1779 : /**
1780 : * Documents belonging to an invisible DocShell must not be painted ever.
1781 : */
1782 1465 : bool IsNeverPainting() {
1783 1465 : return mIsNeverPainting;
1784 : }
1785 :
1786 1 : void SetNeverPainting(bool aNeverPainting) {
1787 1 : mIsNeverPainting = aNeverPainting;
1788 1 : }
1789 :
1790 0 : bool HasPendingReflow() const
1791 0 : { return mObservingLayoutFlushes || mReflowContinueTimer; }
1792 :
1793 : void SyncWindowProperties(nsView* aView);
1794 :
1795 : virtual nsIDocument* GetPrimaryContentDocument() = 0;
1796 :
1797 : // aSheetType is one of the nsIStyleSheetService *_SHEET constants.
1798 : virtual void NotifyStyleSheetServiceSheetAdded(mozilla::StyleSheet* aSheet,
1799 : uint32_t aSheetType) = 0;
1800 : virtual void NotifyStyleSheetServiceSheetRemoved(mozilla::StyleSheet* aSheet,
1801 : uint32_t aSheetType) = 0;
1802 :
1803 : protected:
1804 : friend class nsRefreshDriver;
1805 :
1806 : // IMPORTANT: The ownership implicit in the following member variables
1807 : // has been explicitly checked. If you add any members to this class,
1808 : // please make the ownership explicit (pinkerton, scc).
1809 :
1810 : // These are the same Document and PresContext owned by the DocViewer.
1811 : // we must share ownership.
1812 : nsCOMPtr<nsIDocument> mDocument;
1813 : RefPtr<nsPresContext> mPresContext;
1814 : mozilla::StyleSetHandle mStyleSet; // [OWNS]
1815 : nsCSSFrameConstructor* mFrameConstructor; // [OWNS]
1816 : nsViewManager* mViewManager; // [WEAK] docViewer owns it so I don't have to
1817 : nsPresArena mFrameArena;
1818 : RefPtr<nsFrameSelection> mSelection;
1819 : // Pointer into mFrameConstructor - this is purely so that FrameManager() and
1820 : // GetRootFrame() can be inlined:
1821 : nsFrameManagerBase* mFrameManager;
1822 : mozilla::WeakPtr<nsDocShell> mForwardingContainer;
1823 : #ifdef ACCESSIBILITY
1824 : mozilla::a11y::DocAccessible* mDocAccessible;
1825 : #endif
1826 :
1827 : // At least on Win32 and Mac after interupting a reflow we need to post
1828 : // the resume reflow event off a timer to avoid event starvation because
1829 : // posted messages are processed before other messages when the modal
1830 : // moving/sizing loop is running, see bug 491700 for details.
1831 : nsCOMPtr<nsITimer> mReflowContinueTimer;
1832 :
1833 : #ifdef DEBUG
1834 : nsIFrame* mDrawEventTargetFrame;
1835 :
1836 : // We track allocated pointers in a debug-only hashtable to assert against
1837 : // missing/double frees.
1838 : nsTHashtable<nsPtrHashKey<void>> mAllocatedPointers;
1839 : #endif
1840 :
1841 : // Count of the number of times this presshell has been painted to a window.
1842 : uint64_t mPaintCount;
1843 :
1844 : nsSize mScrollPositionClampingScrollPortSize;
1845 :
1846 : // A list of stack weak frames. This is a pointer to the last item in the list.
1847 : AutoWeakFrame* mAutoWeakFrames;
1848 :
1849 : // A hash table of heap allocated weak frames.
1850 : nsTHashtable<nsPtrHashKey<WeakFrame>> mWeakFrames;
1851 :
1852 : // Most recent canvas background color.
1853 : nscolor mCanvasBackgroundColor;
1854 :
1855 : // Used to force allocation and rendering of proportionally more or
1856 : // less pixels in both dimensions.
1857 : mozilla::Maybe<float> mResolution;
1858 :
1859 : int16_t mSelectionFlags;
1860 :
1861 : // Flags controlling how our document is rendered. These persist
1862 : // between paints and so are tied with retained layer pixels.
1863 : // PresShell flushes retained layers when the rendering state
1864 : // changes in a way that prevents us from being able to (usefully)
1865 : // re-use old pixels.
1866 : RenderFlags mRenderFlags;
1867 : bool mDidInitialize : 1;
1868 : bool mIsDestroying : 1;
1869 : bool mIsReflowing : 1;
1870 :
1871 : // For all documents we initially lock down painting.
1872 : bool mPaintingSuppressed : 1;
1873 :
1874 : bool mIsActive : 1;
1875 : bool mFrozen : 1;
1876 : bool mIsFirstPaint : 1;
1877 : bool mObservesMutationsForPrint : 1;
1878 :
1879 : bool mSuppressInterruptibleReflows : 1;
1880 : bool mScrollPositionClampingScrollPortSizeSet : 1;
1881 :
1882 : // True if a layout flush might not be a no-op
1883 : bool mNeedLayoutFlush : 1;
1884 :
1885 : // True if a style flush might not be a no-op
1886 : bool mNeedStyleFlush : 1;
1887 :
1888 : // True if we're observing the refresh driver for style flushes.
1889 : bool mObservingStyleFlushes: 1;
1890 :
1891 : // True if we're observing the refresh driver for layout flushes, that is, if
1892 : // we have a reflow scheduled.
1893 : //
1894 : // Guaranteed to be false if mReflowContinueTimer is non-null.
1895 : bool mObservingLayoutFlushes: 1;
1896 :
1897 : // True if there are throttled animations that would be processed when
1898 : // performing a flush with mFlushAnimations == true.
1899 : bool mNeedThrottledAnimationFlush : 1;
1900 :
1901 : uint32_t mPresShellId;
1902 :
1903 : static nsIContent* gKeyDownTarget;
1904 :
1905 : // Cached font inflation values. This is done to prevent changing of font
1906 : // inflation until a page is reloaded.
1907 : uint32_t mFontSizeInflationEmPerLine;
1908 : uint32_t mFontSizeInflationMinTwips;
1909 : uint32_t mFontSizeInflationLineThreshold;
1910 : bool mFontSizeInflationForceEnabled;
1911 : bool mFontSizeInflationDisabledInMasterProcess;
1912 : bool mFontSizeInflationEnabled;
1913 :
1914 : // Dirty bit indicating that mFontSizeInflationEnabled needs to be recomputed.
1915 : bool mFontSizeInflationEnabledIsDirty;
1916 :
1917 : bool mPaintingIsFrozen;
1918 :
1919 : // If a document belongs to an invisible DocShell, this flag must be set
1920 : // to true, so we can avoid any paint calls for widget related to this
1921 : // presshell.
1922 : bool mIsNeverPainting;
1923 :
1924 : // Whether we're currently under a FlushPendingNotifications.
1925 : // This is used to handle flush reentry correctly.
1926 : bool mInFlush;
1927 : };
1928 :
1929 : NS_DEFINE_STATIC_IID_ACCESSOR(nsIPresShell, NS_IPRESSHELL_IID)
1930 :
1931 : #endif /* nsIPresShell_h___ */
|