Coverage Report

Created: 2018-09-25 14:53

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