layout/base/nsIPresShell.h

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:214984da2e85
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/EventForwards.h"
24 #include "mozilla/MemoryReporting.h"
25 #include "mozilla/WeakPtr.h"
26 #include "gfxPoint.h"
27 #include "nsTHashtable.h"
28 #include "nsHashKeys.h"
29 #include "nsISupports.h"
30 #include "nsQueryFrame.h"
31 #include "nsCoord.h"
32 #include "nsColor.h"
33 #include "nsCompatibility.h"
34 #include "nsFrameManagerBase.h"
35 #include "mozFlushType.h"
36 #include "nsWeakReference.h"
37 #include <stdio.h> // for FILE definition
38 #include "nsChangeHint.h"
39 #include "nsRefPtrHashtable.h"
40 #include "nsClassHashtable.h"
41 #include "nsPresArena.h"
42 #include "nsIImageLoadingContent.h"
43 #include "nsMargin.h"
44 #include "nsFrameState.h"
45
46 class nsIContent;
47 class nsDocShell;
48 class nsIDocument;
49 class nsIFrame;
50 class nsPresContext;
51 class nsStyleSet;
52 class nsViewManager;
53 class nsView;
54 class nsRenderingContext;
55 class nsIPageSequenceFrame;
56 class nsAString;
57 class nsCaret;
58 class nsFrameSelection;
59 class nsFrameManager;
60 class nsILayoutHistoryState;
61 class nsIReflowCallback;
62 class nsIDOMNode;
63 class nsIntRegion;
64 class nsIStyleSheet;
65 class nsCSSFrameConstructor;
66 class nsISelection;
67 template<class E> class nsCOMArray;
68 class nsWeakFrame;
69 class nsIScrollableFrame;
70 class gfxContext;
71 class nsIDOMEvent;
72 class nsDisplayList;
73 class nsDisplayListBuilder;
74 class nsPIDOMWindow;
75 struct nsPoint;
76 struct nsIntPoint;
77 struct nsIntRect;
78 struct nsRect;
79 class nsRegion;
80 class nsRefreshDriver;
81 class nsARefreshObserver;
82 class nsAPostRefreshObserver;
83 #ifdef ACCESSIBILITY
84 class nsAccessibilityService;
85 namespace mozilla {
86 namespace a11y {
87 class DocAccessible;
88 } // namespace a11y
89 } // namespace mozilla
90 #endif
91 class nsIWidget;
92 struct nsArenaMemoryStats;
93
94 typedef short SelectionType;
95
96 namespace mozilla {
97 class EventStates;
98
99 namespace dom {
100 class Element;
101 class Touch;
102 class Selection;
103 class ShadowRoot;
104 } // namespace dom
105
106 namespace layers {
107 class LayerManager;
108 } // namespace layers
109
110 namespace gfx {
111 class SourceSurface;
112 } // namespace gfx
113 } // namespace mozilla
114
115 // Flags to pass to SetCapturingContent
116 //
117 // when assigning capture, ignore whether capture is allowed or not
118 #define CAPTURE_IGNOREALLOWED 1
119 // true if events should be targeted at the capturing content or its children
120 #define CAPTURE_RETARGETTOELEMENT 2
121 // true if the current capture wants drags to be prevented
122 #define CAPTURE_PREVENTDRAG 4
123 // true when the mouse is pointer locked, and events are sent to locked element
124 #define CAPTURE_POINTERLOCK 8
125
126 typedef struct CapturingContentInfo {
127 // capture should only be allowed during a mousedown event
128 bool mAllowed;
129 bool mPointerLock;
130 bool mRetargetToElement;
131 bool mPreventDrag;
132 nsIContent* mContent;
133 } CapturingContentInfo;
134
135 //61e60df7-128a-4cdd-a684-5f0bd2ceb61f
136 #define NS_IPRESSHELL_IID \
137 { 0x61e60df7, 0x128a, 0x4cdd, \
138 {0xa6, 0x84, 0x5f, 0x0b, 0xd2, 0xce, 0xb6, 0x1f}}
139
140 // debug VerifyReflow flags
141 #define VERIFY_REFLOW_ON 0x01
142 #define VERIFY_REFLOW_NOISY 0x02
143 #define VERIFY_REFLOW_ALL 0x04
144 #define VERIFY_REFLOW_DUMP_COMMANDS 0x08
145 #define VERIFY_REFLOW_NOISY_RC 0x10
146 #define VERIFY_REFLOW_REALLY_NOISY_RC 0x20
147 #define VERIFY_REFLOW_DURING_RESIZE_REFLOW 0x40
148
149 #undef NOISY_INTERRUPTIBLE_REFLOW
150
151 enum nsRectVisibility {
152 nsRectVisibility_kVisible,
153 nsRectVisibility_kAboveViewport,
154 nsRectVisibility_kBelowViewport,
155 nsRectVisibility_kLeftOfViewport,
156 nsRectVisibility_kRightOfViewport
157 };
158
159 /**
160 * Presentation shell interface. Presentation shells are the
161 * controlling point for managing the presentation of a document. The
162 * presentation shell holds a live reference to the document, the
163 * presentation context, the style manager, the style set and the root
164 * frame. <p>
165 *
166 * When this object is Release'd, it will release the document, the
167 * presentation context, the style manager, the style set and the root
168 * frame.
169 */
170
171 class nsIPresShell : public nsISupports
172 {
173 public:
174 NS_DECLARE_STATIC_IID_ACCESSOR(NS_IPRESSHELL_IID)
175
176 protected:
177 typedef mozilla::layers::LayerManager LayerManager;
178 typedef mozilla::gfx::SourceSurface SourceSurface;
179
180 enum eRenderFlag {
181 STATE_IGNORING_VIEWPORT_SCROLLING = 0x1,
182 STATE_DRAWWINDOW_NOT_FLUSHING = 0x2
183 };
184 typedef uint8_t RenderFlags; // for storing the above flags
185
186 public:
187 /**
188 * All callers are responsible for calling |Destroy| after calling
189 * |EndObservingDocument|. It needs to be separate only because form
190 * controls incorrectly store their data in the frames rather than the
191 * content model and printing calls |EndObservingDocument| multiple
192 * times to make form controls behave nicely when printed.
193 */
194 virtual NS_HIDDEN_(void) Destroy() = 0;
195
196 bool IsDestroying() { return mIsDestroying; }
197
198 /**
199 * Make a one-way transition into a "zombie" state. In this state,
200 * no reflow is done, no painting is done, and no refresh driver
201 * ticks are processed. This is a dangerous state: it can leave
202 * areas of the composition target unpainted if callers aren't
203 * careful. (Don't let your zombie presshell out of the shed.)
204 *
205 * This is used in cases where a presshell is created for reasons
206 * other than reflow/painting.
207 */
208 virtual NS_HIDDEN_(void) MakeZombie() = 0;
209
210 /**
211 * All frames owned by the shell are allocated from an arena. They
212 * are also recycled using free lists. Separate free lists are
213 * maintained for each frame type (aID), which must always correspond
214 * to the same aSize value. AllocateFrame returns zero-filled memory.
215 * AllocateFrame is infallible and will abort on out-of-memory.
216 */
217 void* AllocateFrame(nsQueryFrame::FrameIID aID, size_t aSize)
218 {
219 #ifdef DEBUG
220 mPresArenaAllocCount++;
221 #endif
222 void* result = mFrameArena.AllocateByFrameID(aID, aSize);
223 memset(result, 0, aSize);
224 return result;
225 }
226
227 void FreeFrame(nsQueryFrame::FrameIID aID, void* aPtr)
228 {
229 #ifdef DEBUG
230 mPresArenaAllocCount--;
231 #endif
232 if (!mIsDestroying)
233 mFrameArena.FreeByFrameID(aID, aPtr);
234 }
235
236 /**
237 * This is for allocating other types of objects (not frames). Separate free
238 * lists are maintained for each type (aID), which must always correspond to
239 * the same aSize value. AllocateByObjectID returns zero-filled memory.
240 * AllocateByObjectID is infallible and will abort on out-of-memory.
241 */
242 void* AllocateByObjectID(nsPresArena::ObjectID aID, size_t aSize)
243 {
244 #ifdef DEBUG
245 mPresArenaAllocCount++;
246 #endif
247 void* result = mFrameArena.AllocateByObjectID(aID, aSize);
248 memset(result, 0, aSize);
249 return result;
250 }
251
252 void FreeByObjectID(nsPresArena::ObjectID aID, void* aPtr)
253 {
254 #ifdef DEBUG
255 mPresArenaAllocCount--;
256 #endif
257 if (!mIsDestroying)
258 mFrameArena.FreeByObjectID(aID, aPtr);
259 }
260
261 /**
262 * Other objects closely related to the frame tree that are allocated
263 * from a separate set of per-size free lists. Note that different types
264 * of objects that has the same size are allocated from the same list.
265 * AllocateMisc does *not* clear the memory that it returns.
266 * AllocateMisc is infallible and will abort on out-of-memory.
267 *
268 * @deprecated use AllocateByObjectID/FreeByObjectID instead
269 */
270 void* AllocateMisc(size_t aSize)
271 {
272 #ifdef DEBUG
273 mPresArenaAllocCount++;
274 #endif
275 return mFrameArena.AllocateBySize(aSize);
276 }
277
278 void FreeMisc(size_t aSize, void* aPtr)
279 {
280 #ifdef DEBUG
281 mPresArenaAllocCount--;
282 #endif
283 if (!mIsDestroying)
284 mFrameArena.FreeBySize(aSize, aPtr);
285 }
286
287 nsIDocument* GetDocument() const { return mDocument; }
288
289 nsPresContext* GetPresContext() const { return mPresContext; }
290
291 nsViewManager* GetViewManager() const { return mViewManager; }
292
293 #ifdef ACCESSIBILITY
294 /**
295 * Return the document accessible for this pres shell if there is one.
296 */
297 mozilla::a11y::DocAccessible* GetDocAccessible() const
298 {
299 return mDocAccessible;
300 }
301
302 /**
303 * Set the document accessible for this pres shell.
304 */
305 void SetDocAccessible(mozilla::a11y::DocAccessible* aDocAccessible)
306 {
307 mDocAccessible = aDocAccessible;
308 }
309 #endif
310
311 #ifdef MOZILLA_INTERNAL_API
312 nsStyleSet* StyleSet() const { return mStyleSet; }
313
314 nsCSSFrameConstructor* FrameConstructor() const { return mFrameConstructor; }
315
316 nsFrameManager* FrameManager() const {
317 // reinterpret_cast is valid since nsFrameManager does not add
318 // any members over nsFrameManagerBase.
319 return reinterpret_cast<nsFrameManager*>
320 (const_cast<nsIPresShell*>(this)->mFrameManager);
321 }
322
323 #endif
324
325 /* Enable/disable author style level. Disabling author style disables the entire
326 * author level of the cascade, including the HTML preshint level.
327 */
328 // XXX these could easily be inlined, but there is a circular #include
329 // problem with nsStyleSet.
330 NS_HIDDEN_(void) SetAuthorStyleDisabled(bool aDisabled);
331 NS_HIDDEN_(bool) GetAuthorStyleDisabled() const;
332
333 /*
334 * Called when stylesheets are added/removed/enabled/disabled to rebuild
335 * all style data for a given pres shell without necessarily reconstructing
336 * all of the frames. This will not reconstruct style synchronously; if
337 * you need to do that, call FlushPendingNotifications to flush out style
338 * reresolves.
339 * // XXXbz why do we have this on the interface anyway? The only consumer
340 * is calling AddOverrideStyleSheet/RemoveOverrideStyleSheet, and I think
341 * those should just handle reconstructing style data...
342 */
343 virtual NS_HIDDEN_(void) ReconstructStyleDataExternal();
344 NS_HIDDEN_(void) ReconstructStyleDataInternal();
345 #ifdef MOZILLA_INTERNAL_API
346 void ReconstructStyleData() { ReconstructStyleDataInternal(); }
347 #else
348 void ReconstructStyleData() { ReconstructStyleDataExternal(); }
349 #endif
350
351 /** Setup all style rules required to implement preferences
352 * - used for background/text/link colors and link underlining
353 * may be extended for any prefs that are implemented via style rules
354 * - aForceReflow argument is used to force a full reframe to make the rules show
355 * (only used when the current page needs to reflect changed pref rules)
356 *
357 * - initially created for bugs 31816, 20760, 22963
358 */
359 virtual NS_HIDDEN_(nsresult) SetPreferenceStyleRules(bool aForceReflow) = 0;
360
361 /**
362 * FrameSelection will return the Frame based selection API.
363 * You cannot go back and forth anymore with QI between nsIDOM sel and
364 * nsIFrame sel.
365 */
366 already_AddRefed<nsFrameSelection> FrameSelection();
367
368 /**
369 * ConstFrameSelection returns an object which methods are safe to use for
370 * example in nsIFrame code.
371 */
372 const nsFrameSelection* ConstFrameSelection() const { return mSelection; }
373
374 // Make shell be a document observer. If called after Destroy() has
375 // been called on the shell, this will be ignored.
376 virtual NS_HIDDEN_(void) BeginObservingDocument() = 0;
377
378 // Make shell stop being a document observer
379 virtual NS_HIDDEN_(void) EndObservingDocument() = 0;
380
381 /**
382 * Return whether Initialize() was previously called.
383 */
384 bool DidInitialize() const { return mDidInitialize; }
385
386 /**
387 * Perform initialization. Constructs the frame for the root content
388 * object and then enqueues a reflow of the frame model into the
389 * specified width and height.
390 *
391 * The coordinates for aWidth and aHeight must be in standard nscoords.
392 *
393 * Callers of this method must hold a reference to this shell that
394 * is guaranteed to survive through arbitrary script execution.
395 * Calling Initialize can execute arbitrary script.
396 */
397 virtual NS_HIDDEN_(nsresult) Initialize(nscoord aWidth, nscoord aHeight) = 0;
398
399 /**
400 * Reflow the frame model into a new width and height. The
401 * coordinates for aWidth and aHeight must be in standard nscoord's.
402 */
403 virtual NS_HIDDEN_(nsresult) ResizeReflow(nscoord aWidth, nscoord aHeight) = 0;
404 /**
405 * Reflow, and also change presshell state so as to only permit
406 * reflowing off calls to ResizeReflowOverride() in the future.
407 * ResizeReflow() calls are ignored after ResizeReflowOverride().
408 */
409 virtual NS_HIDDEN_(nsresult) ResizeReflowOverride(nscoord aWidth, nscoord aHeight) = 0;
410
411 /**
412 * Returns true if ResizeReflowOverride has been called.
413 */
414 virtual bool GetIsViewportOverridden() = 0;
415
416 /**
417 * Return true if the presshell expects layout flush.
418 */
419 virtual bool IsLayoutFlushObserver() = 0;
420
421 /**
422 * Called when document load completes.
423 */
424 virtual NS_HIDDEN_(void) LoadComplete() = 0;
425
426 /**
427 * This calls through to the frame manager to get the root frame.
428 */
429 virtual NS_HIDDEN_(nsIFrame*) GetRootFrameExternal() const;
430 nsIFrame* GetRootFrame() const {
431 #ifdef MOZILLA_INTERNAL_API
432 return mFrameManager->GetRootFrame();
433 #else
434 return GetRootFrameExternal();
435 #endif
436 }
437
438 /*
439 * Get root scroll frame from FrameManager()->GetRootFrame().
440 */
441 nsIFrame* GetRootScrollFrame() const;
442
443 /*
444 * The same as GetRootScrollFrame, but returns an nsIScrollableFrame
445 */
446 nsIScrollableFrame* GetRootScrollFrameAsScrollable() const;
447
448 /*
449 * The same as GetRootScrollFrame, but returns an nsIScrollableFrame.
450 * Can be called by code not linked into gklayout.
451 */
452 virtual nsIScrollableFrame* GetRootScrollFrameAsScrollableExternal() const;
453
454 /*
455 * Gets nearest scrollable frame from current focused content or DOM
456 * selection if there is no focused content. The frame is scrollable with
457 * overflow:scroll or overflow:auto in some direction when aDirection is
458 * eEither. Otherwise, this returns a nearest frame that is scrollable in
459 * the specified direction.
460 */
461 enum ScrollDirection { eHorizontal, eVertical, eEither };
462 nsIScrollableFrame* GetFrameToScrollAsScrollable(ScrollDirection aDirection);
463
464 /**
465 * Returns the page sequence frame associated with the frame hierarchy.
466 * Returns nullptr if not a paginated view.
467 */
468 virtual NS_HIDDEN_(nsIPageSequenceFrame*) GetPageSequenceFrame() const = 0;
469
470 /**
471 * Gets the real primary frame associated with the content object.
472 *
473 * In the case of absolutely positioned elements and floated elements,
474 * the real primary frame is the frame that is out of the flow and not the
475 * placeholder frame.
476 */
477 virtual NS_HIDDEN_(nsIFrame*) GetRealPrimaryFrameFor(nsIContent* aContent) const = 0;
478
479 /**
480 * Gets the placeholder frame associated with the specified frame. This is
481 * a helper frame that forwards the request to the frame manager.
482 */
483 virtual NS_HIDDEN_(nsIFrame*) GetPlaceholderFrameFor(nsIFrame* aFrame) const = 0;
484
485 /**
486 * Tell the pres shell that a frame needs to be marked dirty and needs
487 * Reflow. It's OK if this is an ancestor of the frame needing reflow as
488 * long as the ancestor chain between them doesn't cross a reflow root.
489 *
490 * The bit to add should be NS_FRAME_IS_DIRTY, NS_FRAME_HAS_DIRTY_CHILDREN
491 * or nsFrameState(0); passing 0 means that dirty bits won't be set on the
492 * frame or its ancestors/descendants, but that intrinsic widths will still
493 * be marked dirty. Passing aIntrinsicDirty = eResize and aBitToAdd = 0
494 * would result in no work being done, so don't do that.
495 */
496 enum IntrinsicDirty {
497 // XXXldb eResize should be renamed
498 eResize, // don't mark any intrinsic widths dirty
499 eTreeChange, // mark intrinsic widths dirty on aFrame and its ancestors
500 eStyleChange // Do eTreeChange, plus all of aFrame's descendants
501 };
502 virtual NS_HIDDEN_(void) FrameNeedsReflow(nsIFrame *aFrame,
503 IntrinsicDirty aIntrinsicDirty,
504 nsFrameState aBitToAdd) = 0;
505
506 /**
507 * Calls FrameNeedsReflow on all fixed position children of the root frame.
508 */
509 virtual void MarkFixedFramesForReflow(IntrinsicDirty aIntrinsicDirty);
510
511 /**
512 * Tell the presshell that the given frame's reflow was interrupted. This
513 * will mark as having dirty children a path from the given frame (inclusive)
514 * to the nearest ancestor with a dirty subtree, or to the reflow root
515 * currently being reflowed if no such ancestor exists (inclusive). This is
516 * to be done immediately after reflow of the current reflow root completes.
517 * This method must only be called during reflow, and the frame it's being
518 * called on must be in the process of being reflowed when it's called. This
519 * method doesn't mark any intrinsic widths dirty and doesn't add any bits
520 * other than NS_FRAME_HAS_DIRTY_CHILDREN.
521 */
522 virtual NS_HIDDEN_(void) FrameNeedsToContinueReflow(nsIFrame *aFrame) = 0;
523
524 virtual NS_HIDDEN_(void) CancelAllPendingReflows() = 0;
525
526 /**
527 * Recreates the frames for a node
528 */
529 virtual NS_HIDDEN_(nsresult) RecreateFramesFor(nsIContent* aContent) = 0;
530
531 void PostRecreateFramesFor(mozilla::dom::Element* aElement);
532 void RestyleForAnimation(mozilla::dom::Element* aElement,
533 nsRestyleHint aHint);
534
535 // ShadowRoot has APIs that can change styles so we only
536 // want to restyle elements in the ShadowRoot and not the whole
537 // document.
538 virtual void RestyleShadowRoot(mozilla::dom::ShadowRoot* aShadowRoot) = 0;
539
540 /**
541 * Determine if it is safe to flush all pending notifications
542 * @param aIsSafeToFlush true if it is safe, false otherwise.
543 *
544 */
545 virtual NS_HIDDEN_(bool) IsSafeToFlush() const = 0;
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 * @param aType the type of notifications to flush
555 */
556 virtual NS_HIDDEN_(void) FlushPendingNotifications(mozFlushType aType) = 0;
557 virtual NS_HIDDEN_(void) FlushPendingNotifications(mozilla::ChangesToFlush aType) = 0;
558
559 /**
560 * Callbacks will be called even if reflow itself fails for
561 * some reason.
562 */
563 virtual NS_HIDDEN_(nsresult) PostReflowCallback(nsIReflowCallback* aCallback) = 0;
564 virtual NS_HIDDEN_(void) CancelReflowCallback(nsIReflowCallback* aCallback) = 0;
565
566 virtual NS_HIDDEN_(void) ClearFrameRefs(nsIFrame* aFrame) = 0;
567
568 /**
569 * Get a reference rendering context. This is a context that should not
570 * be rendered to, but is suitable for measuring text and performing
571 * other non-rendering operations. Guaranteed to return non-null.
572 */
573 virtual already_AddRefed<nsRenderingContext> CreateReferenceRenderingContext() = 0;
574
575 /**
576 * Informs the pres shell that the document is now at the anchor with
577 * the given name. If |aScroll| is true, scrolls the view of the
578 * document so that the anchor with the specified name is displayed at
579 * the top of the window. If |aAnchorName| is empty, then this informs
580 * the pres shell that there is no current target, and |aScroll| must
581 * be false.
582 */
583 virtual NS_HIDDEN_(nsresult) GoToAnchor(const nsAString& aAnchorName, bool aScroll) = 0;
584
585 /**
586 * Tells the presshell to scroll again to the last anchor scrolled to by
587 * GoToAnchor, if any. This scroll only happens if the scroll
588 * position has not changed since the last GoToAnchor. This is called
589 * by nsDocumentViewer::LoadComplete. This clears the last anchor
590 * scrolled to by GoToAnchor (we don't want to keep it alive if it's
591 * removed from the DOM), so don't call this more than once.
592 */
593 virtual NS_HIDDEN_(nsresult) ScrollToAnchor() = 0;
594
595 enum {
596 SCROLL_TOP = 0,
597 SCROLL_BOTTOM = 100,
598 SCROLL_LEFT = 0,
599 SCROLL_RIGHT = 100,
600 SCROLL_CENTER = 50,
601 SCROLL_MINIMUM = -1
602 };
603
604 enum WhenToScroll {
605 SCROLL_ALWAYS,
606 SCROLL_IF_NOT_VISIBLE,
607 SCROLL_IF_NOT_FULLY_VISIBLE
608 };
609 typedef struct ScrollAxis {
610 int16_t mWhereToScroll;
611 WhenToScroll mWhenToScroll : 8;
612 bool mOnlyIfPerceivedScrollableDirection : 1;
613 /**
614 * @param aWhere: Either a percentage or a special value.
615 * nsIPresShell defines:
616 * * (Default) SCROLL_MINIMUM = -1: The visible area is
617 * scrolled to show the entire frame. If the frame is too
618 * large, the top and left edges are given precedence.
619 * * SCROLL_TOP = 0: The frame's upper edge is aligned with the
620 * top edge of the visible area.
621 * * SCROLL_BOTTOM = 100: The frame's bottom edge is aligned
622 * with the bottom edge of the visible area.
623 * * SCROLL_LEFT = 0: The frame's left edge is aligned with the
624 * left edge of the visible area.
625 * * SCROLL_RIGHT = 100: The frame's right edge is aligned with
626 * the right edge of the visible area.
627 * * SCROLL_CENTER = 50: The frame is centered along the axis
628 * the ScrollAxis is used for.
629 *
630 * Other values are treated as a percentage, and the point
631 * "percent" down the frame is placed at the point "percent"
632 * down the visible area.
633 * @param aWhen:
634 * * (Default) SCROLL_IF_NOT_FULLY_VISIBLE: Move the frame only
635 * if it is not fully visible (including if it's not visible
636 * at all). Note that in this case if the frame is too large to
637 * fit in view, it will only be scrolled if more of it can fit
638 * than is already in view.
639 * * SCROLL_IF_NOT_VISIBLE: Move the frame only if none of it
640 * is visible.
641 * * SCROLL_ALWAYS: Move the frame regardless of its current
642 * visibility.
643 * @param aOnlyIfPerceivedScrollableDirection:
644 * If the direction is not a perceived scrollable direction (i.e.
645 * no scrollbar showing and less than one device pixel of
646 * scrollable distance), don't scroll. Defaults to false.
647 */
648 ScrollAxis(int16_t aWhere = SCROLL_MINIMUM,
649 WhenToScroll aWhen = SCROLL_IF_NOT_FULLY_VISIBLE,
650 bool aOnlyIfPerceivedScrollableDirection = false) :
651 mWhereToScroll(aWhere), mWhenToScroll(aWhen),
652 mOnlyIfPerceivedScrollableDirection(aOnlyIfPerceivedScrollableDirection)
653 {}
654 } ScrollAxis;
655 /**
656 * Scrolls the view of the document so that the primary frame of the content
657 * is displayed in the window. Layout is flushed before scrolling.
658 *
659 * @param aContent The content object of which primary frame should be
660 * scrolled into view.
661 * @param aVertical How to align the frame vertically and when to do so.
662 * This is a ScrollAxis of Where and When.
663 * @param aHorizontal How to align the frame horizontally and when to do so.
664 * This is a ScrollAxis of Where and When.
665 * @param aFlags If SCROLL_FIRST_ANCESTOR_ONLY is set, only the nearest
666 * scrollable ancestor is scrolled, otherwise all
667 * scrollable ancestors may be scrolled if necessary.
668 * If SCROLL_OVERFLOW_HIDDEN is set then we may scroll in a
669 * direction even if overflow:hidden is specified in that
670 * direction; otherwise we will not scroll in that direction
671 * when overflow:hidden is set for that direction.
672 * If SCROLL_NO_PARENT_FRAMES is set then we only scroll
673 * nodes in this document, not in any parent documents which
674 * contain this document in a iframe or the like.
675 */
676 virtual NS_HIDDEN_(nsresult) ScrollContentIntoView(nsIContent* aContent,
677 ScrollAxis aVertical,
678 ScrollAxis aHorizontal,
679 uint32_t aFlags) = 0;
680
681 enum {
682 SCROLL_FIRST_ANCESTOR_ONLY = 0x01,
683 SCROLL_OVERFLOW_HIDDEN = 0x02,
684 SCROLL_NO_PARENT_FRAMES = 0x04
685 };
686 /**
687 * Scrolls the view of the document so that the given area of a frame
688 * is visible, if possible. Layout is not flushed before scrolling.
689 *
690 * @param aRect relative to aFrame
691 * @param aVertical see ScrollContentIntoView and ScrollAxis
692 * @param aHorizontal see ScrollContentIntoView and ScrollAxis
693 * @param aFlags if SCROLL_FIRST_ANCESTOR_ONLY is set, only the
694 * nearest scrollable ancestor is scrolled, otherwise all
695 * scrollable ancestors may be scrolled if necessary
696 * if SCROLL_OVERFLOW_HIDDEN is set then we may scroll in a direction
697 * even if overflow:hidden is specified in that direction; otherwise
698 * we will not scroll in that direction when overflow:hidden is
699 * set for that direction
700 * If SCROLL_NO_PARENT_FRAMES is set then we only scroll
701 * nodes in this document, not in any parent documents which
702 * contain this document in a iframe or the like.
703 * @return true if any scrolling happened, false if no scrolling happened
704 */
705 virtual bool ScrollFrameRectIntoView(nsIFrame* aFrame,
706 const nsRect& aRect,
707 ScrollAxis aVertical,
708 ScrollAxis aHorizontal,
709 uint32_t aFlags) = 0;
710
711 /**
712 * Determine if a rectangle specified in the frame's coordinate system
713 * intersects the viewport "enough" to be considered visible.
714 * @param aFrame frame that aRect coordinates are specified relative to
715 * @param aRect rectangle in twips to test for visibility
716 * @param aMinTwips is the minimum distance in from the edge of the viewport
717 * that an object must be to be counted visible
718 * @return nsRectVisibility_kVisible if the rect is visible
719 * nsRectVisibility_kAboveViewport
720 * nsRectVisibility_kBelowViewport
721 * nsRectVisibility_kLeftOfViewport
722 * nsRectVisibility_kRightOfViewport rectangle is outside the viewport
723 * in the specified direction
724 */
725 virtual nsRectVisibility GetRectVisibility(nsIFrame *aFrame,
726 const nsRect &aRect,
727 nscoord aMinTwips) const = 0;
728
729 /**
730 * Suppress notification of the frame manager that frames are
731 * being destroyed.
732 */
733 virtual NS_HIDDEN_(void) SetIgnoreFrameDestruction(bool aIgnore) = 0;
734
735 /**
736 * Notification sent by a frame informing the pres shell that it is about to
737 * be destroyed.
738 * This allows any outstanding references to the frame to be cleaned up
739 */
740 virtual NS_HIDDEN_(void) NotifyDestroyingFrame(nsIFrame* aFrame) = 0;
741
742 /**
743 * Get the caret, if it exists. AddRefs it.
744 */
745 virtual NS_HIDDEN_(already_AddRefed<nsCaret>) GetCaret() const = 0;
746
747 /**
748 * Invalidate the caret's current position if it's outside of its frame's
749 * boundaries. This function is useful if you're batching selection
750 * notifications and might remove the caret's frame out from under it.
751 */
752 virtual NS_HIDDEN_(void) MaybeInvalidateCaretPosition() = 0;
753
754 /**
755 * Set the current caret to a new caret. To undo this, call RestoreCaret.
756 */
757 virtual void SetCaret(nsCaret *aNewCaret) = 0;
758
759 /**
760 * Restore the caret to the original caret that this pres shell was created
761 * with.
762 */
763 virtual void RestoreCaret() = 0;
764
765 /**
766 * Should the images have borders etc. Actual visual effects are determined
767 * by the frames. Visual effects may not effect layout, only display.
768 * Takes effect on next repaint, does not force a repaint itself.
769 *
770 * @param aInEnable if true, visual selection effects are enabled
771 * if false visual selection effects are disabled
772 */
773 NS_IMETHOD SetSelectionFlags(int16_t aInEnable) = 0;
774
775 /**
776 * Gets the current state of non text selection effects
777 * @return current state of non text selection,
778 * as set by SetDisplayNonTextSelection
779 */
780 int16_t GetSelectionFlags() const { return mSelectionFlags; }
781
782 virtual mozilla::dom::Selection* GetCurrentSelection(SelectionType aType) = 0;
783
784 /**
785 * Interface to dispatch events via the presshell
786 * @note The caller must have a strong reference to the PresShell.
787 */
788 virtual NS_HIDDEN_(nsresult) HandleEventWithTarget(
789 mozilla::WidgetEvent* aEvent,
790 nsIFrame* aFrame,
791 nsIContent* aContent,
792 nsEventStatus* aStatus) = 0;
793
794 /**
795 * Dispatch event to content only (NOT full processing)
796 * @note The caller must have a strong reference to the PresShell.
797 */
798 virtual NS_HIDDEN_(nsresult) HandleDOMEventWithTarget(
799 nsIContent* aTargetContent,
800 mozilla::WidgetEvent* aEvent,
801 nsEventStatus* aStatus) = 0;
802
803 /**
804 * Dispatch event to content only (NOT full processing)
805 * @note The caller must have a strong reference to the PresShell.
806 */
807 virtual NS_HIDDEN_(nsresult) HandleDOMEventWithTarget(nsIContent* aTargetContent,
808 nsIDOMEvent* aEvent,
809 nsEventStatus* aStatus) = 0;
810
811 /**
812 * Gets the current target event frame from the PresShell
813 */
814 virtual NS_HIDDEN_(nsIFrame*) GetEventTargetFrame() = 0;
815
816 /**
817 * Gets the current target event frame from the PresShell
818 */
819 virtual NS_HIDDEN_(already_AddRefed<nsIContent>) GetEventTargetContent(
820 mozilla::WidgetEvent* aEvent) = 0;
821
822 /**
823 * Get and set the history state for the current document
824 */
825
826 virtual NS_HIDDEN_(nsresult) CaptureHistoryState(nsILayoutHistoryState** aLayoutHistoryState) = 0;
827
828 /**
829 * Determine if reflow is currently locked
830 * returns true if reflow is locked, false otherwise
831 */
832 bool IsReflowLocked() const { return mIsReflowing; }
833
834 /**
835 * Called to find out if painting is suppressed for this presshell. If it is suppressd,
836 * we don't allow the painting of any layer but the background, and we don't
837 * recur into our children.
838 */
839 bool IsPaintingSuppressed() const { return mPaintingSuppressed; }
840
841 /**
842 * Pause painting by freezing the refresh driver of this and all parent
843 * presentations. This may not have the desired effect if this pres shell
844 * has its own refresh driver.
845 */
846 virtual void PausePainting() = 0;
847
848 /**
849 * Resume painting by thawing the refresh driver of this and all parent
850 * presentations. This may not have the desired effect if this pres shell
851 * has its own refresh driver.
852 */
853 virtual void ResumePainting() = 0;
854
855 /**
856 * Unsuppress painting.
857 */
858 virtual NS_HIDDEN_(void) UnsuppressPainting() = 0;
859
860 /**
861 * Called to disable nsITheme support in a specific presshell.
862 */
863 void DisableThemeSupport()
864 {
865 // Doesn't have to be dynamic. Just set the bool.
866 mIsThemeSupportDisabled = true;
867 }
868
869 /**
870 * Indicates whether theme support is enabled.
871 */
872 bool IsThemeSupportEnabled() const { return !mIsThemeSupportDisabled; }
873
874 /**
875 * Get the set of agent style sheets for this presentation
876 */
877 virtual nsresult GetAgentStyleSheets(nsCOMArray<nsIStyleSheet>& aSheets) = 0;
878
879 /**
880 * Replace the set of agent style sheets
881 */
882 virtual nsresult SetAgentStyleSheets(const nsCOMArray<nsIStyleSheet>& aSheets) = 0;
883
884 /**
885 * Add an override style sheet for this presentation
886 */
887 virtual nsresult AddOverrideStyleSheet(nsIStyleSheet *aSheet) = 0;
888
889 /**
890 * Remove an override style sheet
891 */
892 virtual nsresult RemoveOverrideStyleSheet(nsIStyleSheet *aSheet) = 0;
893
894 /**
895 * Reconstruct frames for all elements in the document
896 */
897 virtual nsresult ReconstructFrames() = 0;
898
899 /**
900 * Notify that a content node's state has changed
901 */
902 virtual void ContentStateChanged(nsIDocument* aDocument,
903 nsIContent* aContent,
904 mozilla::EventStates aStateMask) = 0;
905
906 /**
907 * See if reflow verification is enabled. To enable reflow verification add
908 * "verifyreflow:1" to your NSPR_LOG_MODULES environment variable
909 * (any non-zero debug level will work). Or, call SetVerifyReflowEnable
910 * with true.
911 */
912 static bool GetVerifyReflowEnable();
913
914 /**
915 * Set the verify-reflow enable flag.
916 */
917 static void SetVerifyReflowEnable(bool aEnabled);
918
919 virtual nsIFrame* GetAbsoluteContainingBlock(nsIFrame* aFrame);
920
921 #ifdef MOZ_REFLOW_PERF
922 virtual NS_HIDDEN_(void) DumpReflows() = 0;
923 virtual NS_HIDDEN_(void) CountReflows(const char * aName, nsIFrame * aFrame) = 0;
924 virtual NS_HIDDEN_(void) PaintCount(const char * aName,
925 nsRenderingContext* aRenderingContext,
926 nsPresContext * aPresContext,
927 nsIFrame * aFrame,
928 const nsPoint& aOffset,
929 uint32_t aColor) = 0;
930 virtual NS_HIDDEN_(void) SetPaintFrameCount(bool aOn) = 0;
931 virtual bool IsPaintingFrameCounts() = 0;
932 #endif
933
934 #ifdef DEBUG
935 // Debugging hooks
936 virtual void ListStyleContexts(nsIFrame *aRootFrame, FILE *out,
937 int32_t aIndent = 0) = 0;
938
939 virtual void ListStyleSheets(FILE *out, int32_t aIndent = 0) = 0;
940 virtual void VerifyStyleTree() = 0;
941 #endif
942
943 #ifdef ACCESSIBILITY
944 /**
945 * Return true if accessibility is active.
946 */
947 static bool IsAccessibilityActive();
948
949 /**
950 * Return accessibility service if accessibility is active.
951 */
952 static nsAccessibilityService* AccService();
953 #endif
954
955 /**
956 * Stop all active elements (plugins and the caret) in this presentation and
957 * in the presentations of subdocuments. Resets painting to a suppressed state.
958 * XXX this should include image animations
959 */
960 virtual void Freeze() = 0;
961 bool IsFrozen() { return mFrozen; }
962
963 /**
964 * Restarts active elements (plugins) in this presentation and in the
965 * presentations of subdocuments, then do a full invalidate of the content area.
966 */
967 virtual void Thaw() = 0;
968
969 virtual void FireOrClearDelayedEvents(bool aFireEvents) = 0;
970
971 /**
972 * When this shell is disconnected from its containing docshell, we
973 * lose our container pointer. However, we'd still like to be able to target
974 * user events at the docshell's parent. This pointer allows us to do that.
975 * It should not be used for any other purpose.
976 */
977 void SetForwardingContainer(const mozilla::WeakPtr<nsDocShell> &aContainer);
978
979 /**
980 * Render the document into an arbitrary gfxContext
981 * Designed for getting a picture of a document or a piece of a document
982 * Note that callers will generally want to call FlushPendingNotifications
983 * to get an up-to-date view of the document
984 * @param aRect is the region to capture into the offscreen buffer, in the
985 * root frame's coordinate system (if aIgnoreViewportScrolling is false)
986 * or in the root scrolled frame's coordinate system
987 * (if aIgnoreViewportScrolling is true). The coordinates are in appunits.
988 * @param aFlags see below;
989 * set RENDER_IS_UNTRUSTED if the contents may be passed to malicious
990 * agents. E.g. we might choose not to paint the contents of sensitive widgets
991 * such as the file name in a file upload widget, and we might choose not
992 * to paint themes.
993 * set RENDER_IGNORE_VIEWPORT_SCROLLING to ignore
994 * clipping/scrolling/scrollbar painting due to scrolling in the viewport
995 * set RENDER_CARET to draw the caret if one would be visible
996 * (by default the caret is never drawn)
997 * set RENDER_USE_LAYER_MANAGER to force rendering to go through
998 * the layer manager for the window. This may be unexpectedly slow
999 * (if the layer manager must read back data from the GPU) or low-quality
1000 * (if the layer manager reads back pixel data and scales it
1001 * instead of rendering using the appropriate scaling). It may also
1002 * slow everything down if the area rendered does not correspond to the
1003 * normal visible area of the window.
1004 * set RENDER_ASYNC_DECODE_IMAGES to avoid having images synchronously
1005 * decoded during rendering.
1006 * (by default images decode synchronously with RenderDocument)
1007 * set RENDER_DOCUMENT_RELATIVE to interpret |aRect| relative to the
1008 * document instead of the CSS viewport
1009 * @param aBackgroundColor a background color to render onto
1010 * @param aRenderedContext the gfxContext to render to. We render so that
1011 * one CSS pixel in the source document is rendered to one unit in the current
1012 * transform.
1013 */
1014 enum {
1015 RENDER_IS_UNTRUSTED = 0x01,
1016 RENDER_IGNORE_VIEWPORT_SCROLLING = 0x02,
1017 RENDER_CARET = 0x04,
1018 RENDER_USE_WIDGET_LAYERS = 0x08,
1019 RENDER_ASYNC_DECODE_IMAGES = 0x10,
1020 RENDER_DOCUMENT_RELATIVE = 0x20,
1021 RENDER_DRAWWINDOW_NOT_FLUSHING = 0x40
1022 };
1023 virtual NS_HIDDEN_(nsresult) RenderDocument(const nsRect& aRect, uint32_t aFlags,
1024 nscolor aBackgroundColor,
1025 gfxContext* aRenderedContext) = 0;
1026
1027 /**
1028 * Renders a node aNode to a surface and returns it. The aRegion may be used
1029 * to clip the rendering. This region is measured in CSS pixels from the
1030 * edge of the presshell area. The aPoint, aScreenRect and aSurface
1031 * arguments function in a similar manner as RenderSelection.
1032 */
1033 virtual mozilla::TemporaryRef<SourceSurface>
1034 RenderNode(nsIDOMNode* aNode,
1035 nsIntRegion* aRegion,
1036 nsIntPoint& aPoint,
1037 nsIntRect* aScreenRect) = 0;
1038
1039 /**
1040 * Renders a selection to a surface and returns it. This method is primarily
1041 * intended to create the drag feedback when dragging a selection.
1042 *
1043 * aScreenRect will be filled in with the bounding rectangle of the
1044 * selection area on screen.
1045 *
1046 * If the area of the selection is large, the image will be scaled down.
1047 * The argument aPoint is used in this case as a reference point when
1048 * determining the new screen rectangle after scaling. Typically, this
1049 * will be the mouse position, so that the screen rectangle is positioned
1050 * such that the mouse is over the same point in the scaled image as in
1051 * the original. When scaling does not occur, the mouse point isn't used
1052 * as the position can be determined from the displayed frames.
1053 */
1054 virtual mozilla::TemporaryRef<SourceSurface>
1055 RenderSelection(nsISelection* aSelection,
1056 nsIntPoint& aPoint,
1057 nsIntRect* aScreenRect) = 0;
1058
1059 void AddWeakFrameInternal(nsWeakFrame* aWeakFrame);
1060 virtual void AddWeakFrameExternal(nsWeakFrame* aWeakFrame);
1061
1062 void AddWeakFrame(nsWeakFrame* aWeakFrame)
1063 {
1064 #ifdef MOZILLA_INTERNAL_API
1065 AddWeakFrameInternal(aWeakFrame);
1066 #else
1067 AddWeakFrameExternal(aWeakFrame);
1068 #endif
1069 }
1070
1071 void RemoveWeakFrameInternal(nsWeakFrame* aWeakFrame);
1072 virtual void RemoveWeakFrameExternal(nsWeakFrame* aWeakFrame);
1073
1074 void RemoveWeakFrame(nsWeakFrame* aWeakFrame)
1075 {
1076 #ifdef MOZILLA_INTERNAL_API
1077 RemoveWeakFrameInternal(aWeakFrame);
1078 #else
1079 RemoveWeakFrameExternal(aWeakFrame);
1080 #endif
1081 }
1082
1083 #ifdef DEBUG
1084 nsIFrame* GetDrawEventTargetFrame() { return mDrawEventTargetFrame; }
1085 #endif
1086
1087 /**
1088 * Stop or restart non synthetic test mouse event handling on *all*
1089 * presShells.
1090 *
1091 * @param aDisable If true, disable all non synthetic test mouse
1092 * events on all presShells. Otherwise, enable them.
1093 */
1094 virtual NS_HIDDEN_(void) DisableNonTestMouseEvents(bool aDisable) = 0;
1095
1096 /**
1097 * Record the background color of the most recently drawn canvas. This color
1098 * is composited on top of the user's default background color and then used
1099 * to draw the background color of the canvas. See PresShell::Paint,
1100 * PresShell::PaintDefaultBackground, and nsDocShell::SetupNewViewer;
1101 * bug 488242, bug 476557 and other bugs mentioned there.
1102 */
1103 void SetCanvasBackground(nscolor aColor) { mCanvasBackgroundColor = aColor; }
1104 nscolor GetCanvasBackground() { return mCanvasBackgroundColor; }
1105
1106 /**
1107 * Use the current frame tree (if it exists) to update the background
1108 * color of the most recently drawn canvas.
1109 */
1110 virtual void UpdateCanvasBackground() = 0;
1111
1112 /**
1113 * Add a solid color item to the bottom of aList with frame aFrame and bounds
1114 * aBounds. Checks first if this needs to be done by checking if aFrame is a
1115 * canvas frame (if the FORCE_DRAW flag is passed then this check is skipped).
1116 * aBackstopColor is composed behind the background color of the canvas, it is
1117 * transparent by default.
1118 */
1119 enum {
1120 FORCE_DRAW = 0x01
1121 };
1122 virtual void AddCanvasBackgroundColorItem(nsDisplayListBuilder& aBuilder,
1123 nsDisplayList& aList,
1124 nsIFrame* aFrame,
1125 const nsRect& aBounds,
1126 nscolor aBackstopColor = NS_RGBA(0,0,0,0),
1127 uint32_t aFlags = 0) = 0;
1128
1129
1130 /**
1131 * Add a solid color item to the bottom of aList with frame aFrame and
1132 * bounds aBounds representing the dark grey background behind the page of a
1133 * print preview presentation.
1134 */
1135 virtual void AddPrintPreviewBackgroundItem(nsDisplayListBuilder& aBuilder,
1136 nsDisplayList& aList,
1137 nsIFrame* aFrame,
1138 const nsRect& aBounds) = 0;
1139
1140 /**
1141 * Computes the backstop color for the view: transparent if in a transparent
1142 * widget, otherwise the PresContext default background color. This color is
1143 * only visible if the contents of the view as a whole are translucent.
1144 */
1145 virtual nscolor ComputeBackstopColor(nsView* aDisplayRoot) = 0;
1146
1147 void ObserveNativeAnonMutationsForPrint(bool aObserve)
1148 {
1149 mObservesMutationsForPrint = aObserve;
1150 }
1151 bool ObservesNativeAnonMutationsForPrint()
1152 {
1153 return mObservesMutationsForPrint;
1154 }
1155
1156 virtual nsresult SetIsActive(bool aIsActive) = 0;
1157
1158 bool IsActive()
1159 {
1160 return mIsActive;
1161 }
1162
1163 // mouse capturing
1164
1165 static CapturingContentInfo gCaptureInfo;
1166
1167 static nsRefPtrHashtable<nsUint32HashKey, mozilla::dom::Touch>* gCaptureTouchList;
1168 static bool gPreventMouseEvents;
1169
1170 // Keeps a map between pointerId and element that currently capturing pointer
1171 // with such pointerId. If pointerId is absent in this map then nobody is
1172 // capturing it.
1173 static nsRefPtrHashtable<nsUint32HashKey, nsIContent>* gPointerCaptureList;
1174
1175 struct PointerInfo
1176 {
1177 bool mActiveState;
1178 uint16_t mPointerType;
1179 PointerInfo(bool aActiveState, uint16_t aPointerType) :
1180 mActiveState(aActiveState), mPointerType(aPointerType) {}
1181 };
1182 // Keeps information about pointers such as pointerId, activeState, pointerType
1183 static nsClassHashtable<nsUint32HashKey, PointerInfo>* gActivePointersIds;
1184
1185 static void DispatchGotOrLostPointerCaptureEvent(bool aIsGotCapture,
1186 uint32_t aPointerId,
1187 nsIContent* aCaptureTarget);
1188 static void SetPointerCapturingContent(uint32_t aPointerId, nsIContent* aContent);
1189 static void ReleasePointerCapturingContent(uint32_t aPointerId, nsIContent* aContent);
1190 static nsIContent* GetPointerCapturingContent(uint32_t aPointerId);
1191
1192 // GetPointerInfo returns true if pointer with aPointerId is situated in device, false otherwise.
1193 // aActiveState is additional information, which shows state of pointer like button state for mouse.
1194 static bool GetPointerInfo(uint32_t aPointerId, bool& aActiveState);
1195
1196 /**
1197 * When capturing content is set, it traps all mouse events and retargets
1198 * them at this content node. If capturing is not allowed
1199 * (gCaptureInfo.mAllowed is false), then capturing is not set. However, if
1200 * the CAPTURE_IGNOREALLOWED flag is set, the allowed state is ignored and
1201 * capturing is set regardless. To disable capture, pass null for the value
1202 * of aContent.
1203 *
1204 * If CAPTURE_RETARGETTOELEMENT is set, all mouse events are targeted at
1205 * aContent only. Otherwise, mouse events are targeted at aContent or its
1206 * descendants. That is, descendants of aContent receive mouse events as
1207 * they normally would, but mouse events outside of aContent are retargeted
1208 * to aContent.
1209 *
1210 * If CAPTURE_PREVENTDRAG is set then drags are prevented from starting while
1211 * this capture is active.
1212 *
1213 * If CAPTURE_POINTERLOCK is set, similar to CAPTURE_RETARGETTOELEMENT, then
1214 * events are targeted at aContent, but capturing is held more strongly (i.e.,
1215 * calls to SetCapturingContent won't unlock unless CAPTURE_POINTERLOCK is
1216 * set again).
1217 */
1218 static void SetCapturingContent(nsIContent* aContent, uint8_t aFlags);
1219
1220 /**
1221 * Return the active content currently capturing the mouse if any.
1222 */
1223 static nsIContent* GetCapturingContent()
1224 {
1225 return gCaptureInfo.mContent;
1226 }
1227
1228 /**
1229 * Allow or disallow mouse capturing.
1230 */
1231 static void AllowMouseCapture(bool aAllowed)
1232 {
1233 gCaptureInfo.mAllowed = aAllowed;
1234 }
1235
1236 /**
1237 * Returns true if there is an active mouse capture that wants to prevent
1238 * drags.
1239 */
1240 static bool IsMouseCapturePreventingDrag()
1241 {
1242 return gCaptureInfo.mPreventDrag && gCaptureInfo.mContent;
1243 }
1244
1245 /**
1246 * Keep track of how many times this presshell has been rendered to
1247 * a window.
1248 */
1249 uint64_t GetPaintCount() { return mPaintCount; }
1250 void IncrementPaintCount() { ++mPaintCount; }
1251
1252 /**
1253 * Get the root DOM window of this presShell.
1254 */
1255 virtual already_AddRefed<nsPIDOMWindow> GetRootWindow() = 0;
1256
1257 /**
1258 * Get the layer manager for the widget of the root view, if it has
1259 * one.
1260 */
1261 virtual LayerManager* GetLayerManager() = 0;
1262
1263 /**
1264 * Track whether we're ignoring viewport scrolling for the purposes
1265 * of painting. If we are ignoring, then layers aren't clipped to
1266 * the CSS viewport and scrollbars aren't drawn.
1267 */
1268 virtual void SetIgnoreViewportScrolling(bool aIgnore) = 0;
1269 bool IgnoringViewportScrolling() const
1270 { return mRenderFlags & STATE_IGNORING_VIEWPORT_SCROLLING; }
1271
1272 /**
1273 * Set a "resolution" for the document, which if not 1.0 will
1274 * allocate more or fewer pixels for rescalable content by a factor
1275 * of |resolution| in both dimensions. Return NS_OK iff the
1276 * resolution bounds are sane, and the resolution of this was
1277 * actually updated.
1278 *
1279 * The resolution defaults to 1.0.
1280 */
1281 virtual nsresult SetResolution(float aXResolution, float aYResolution) = 0;
1282 gfxSize GetResolution() { return gfxSize(mXResolution, mYResolution); }
1283 float GetXResolution() { return mXResolution; }
1284 float GetYResolution() { return mYResolution; }
1285 virtual gfxSize GetCumulativeResolution() = 0;
1286
1287 /**
1288 * Returns whether we are in a DrawWindow() call that used the
1289 * DRAWWINDOW_DO_NOT_FLUSH flag.
1290 */
1291 bool InDrawWindowNotFlushing() const
1292 { return mRenderFlags & STATE_DRAWWINDOW_NOT_FLUSHING; }
1293
1294 /**
1295 * Set the isFirstPaint flag.
1296 */
1297 void SetIsFirstPaint(bool aIsFirstPaint) { mIsFirstPaint = aIsFirstPaint; }
1298
1299 /**
1300 * Get the isFirstPaint flag.
1301 */
1302 bool GetIsFirstPaint() const { return mIsFirstPaint; }
1303
1304 uint32_t GetPresShellId() { return mPresShellId; }
1305
1306 /**
1307 * Dispatch a mouse move event based on the most recent mouse position if
1308 * this PresShell is visible. This is used when the contents of the page
1309 * moved (aFromScroll is false) or scrolled (aFromScroll is true).
1310 */
1311 virtual void SynthesizeMouseMove(bool aFromScroll) = 0;
1312
1313 enum PaintFlags {
1314 /* Update the layer tree and paint ThebesLayers. If this is not specified,
1315 * we may still have to do it if the layer tree lost ThebesLayer contents
1316 * we need for compositing. */
1317 PAINT_LAYERS = 0x01,
1318 /* Composite layers to the window. */
1319 PAINT_COMPOSITE = 0x02,
1320 };
1321 virtual void Paint(nsView* aViewToPaint, const nsRegion& aDirtyRegion,
1322 uint32_t aFlags) = 0;
1323 virtual nsresult HandleEvent(nsIFrame* aFrame,
1324 mozilla::WidgetGUIEvent* aEvent,
1325 bool aDontRetargetEvents,
1326 nsEventStatus* aEventStatus) = 0;
1327 virtual bool ShouldIgnoreInvalidation() = 0;
1328 /**
1329 * Notify that we're going to call Paint with PAINT_LAYERS
1330 * on the pres shell for a widget (which might not be this one, since
1331 * WillPaint is called on all presshells in the same toplevel window as the
1332 * painted widget). This is issued at a time when it's safe to modify
1333 * widget geometry.
1334 */
1335 virtual void WillPaint() = 0;
1336 /**
1337 * Notify that we're going to call Paint with PAINT_COMPOSITE.
1338 * Fires on the presshell for the painted widget.
1339 * This is issued at a time when it's safe to modify widget geometry.
1340 */
1341 virtual void WillPaintWindow() = 0;
1342 /**
1343 * Notify that we called Paint with PAINT_COMPOSITE.
1344 * Fires on the presshell for the painted widget.
1345 * This is issued at a time when it's safe to modify widget geometry.
1346 */
1347 virtual void DidPaintWindow() = 0;
1348
1349 /**
1350 * Ensures that the refresh driver is running, and schedules a view
1351 * manager flush on the next tick.
1352 *
1353 * @param aType PAINT_DELAYED_COMPRESS : Schedule a paint to be executed after a delay, and
1354 * put FrameLayerBuilder in 'compressed' mode that avoids short cut optimizations.
1355 */
1356 enum PaintType {
1357 PAINT_DEFAULT,
1358 PAINT_DELAYED_COMPRESS
1359 };
1360 virtual void ScheduleViewManagerFlush(PaintType aType = PAINT_DEFAULT) = 0;
1361 virtual void ClearMouseCaptureOnView(nsView* aView) = 0;
1362 virtual bool IsVisible() = 0;
1363 virtual void DispatchSynthMouseMove(mozilla::WidgetGUIEvent* aEvent,
1364 bool aFlushOnHoverChange) = 0;
1365
1366 virtual void AddSizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf,
1367 nsArenaMemoryStats *aArenaObjectsSize,
1368 size_t *aPresShellSize,
1369 size_t *aStyleSetsSize,
1370 size_t *aTextRunsSize,
1371 size_t *aPresContextSize) = 0;
1372
1373 /**
1374 * Methods that retrieve the cached font inflation preferences.
1375 */
1376 uint32_t FontSizeInflationEmPerLine() const {
1377 return mFontSizeInflationEmPerLine;
1378 }
1379
1380 uint32_t FontSizeInflationMinTwips() const {
1381 return mFontSizeInflationMinTwips;
1382 }
1383
1384 uint32_t FontSizeInflationLineThreshold() const {
1385 return mFontSizeInflationLineThreshold;
1386 }
1387
1388 bool FontSizeInflationForceEnabled() const {
1389 return mFontSizeInflationForceEnabled;
1390 }
1391
1392 bool FontSizeInflationDisabledInMasterProcess() const {
1393 return mFontSizeInflationDisabledInMasterProcess;
1394 }
1395
1396 /**
1397 * Determine if font size inflation is enabled. This value is cached until
1398 * it becomes dirty.
1399 *
1400 * @returns true, if font size inflation is enabled; false otherwise.
1401 */
1402 bool FontSizeInflationEnabled();
1403
1404 /**
1405 * Notify the pres shell that an event occurred making the current value of
1406 * mFontSizeInflationEnabled invalid. This will schedule a recomputation of
1407 * whether font size inflation is enabled on the next call to
1408 * FontSizeInflationEnabled().
1409 */
1410 void NotifyFontSizeInflationEnabledIsDirty()
1411 {
1412 mFontSizeInflationEnabledIsDirty = true;
1413 }
1414
1415 virtual void AddInvalidateHiddenPresShellObserver(nsRefreshDriver *aDriver) = 0;
1416
1417 void InvalidatePresShellIfHidden();
1418 void CancelInvalidatePresShellIfHidden();
1419
1420 // Schedule an update of the list of visible images.
1421 virtual void ScheduleImageVisibilityUpdate() = 0;
1422
1423 // Clears the current list of visible images on this presshell and replaces it
1424 // with images that are in the display list aList.
1425 virtual void RebuildImageVisibility(const nsDisplayList& aList) = 0;
1426
1427 // Ensures the image is in the list of visible images.
1428 virtual void EnsureImageInVisibleList(nsIImageLoadingContent* aImage) = 0;
1429
1430 // Removes the image from the list of visible images if it is present there.
1431 virtual void RemoveImageFromVisibleList(nsIImageLoadingContent* aImage) = 0;
1432
1433 // Whether we should assume all images are visible.
1434 virtual bool AssumeAllImagesVisible() = 0;
1435
1436 /**
1437 * Refresh observer management.
1438 */
1439 protected:
1440 virtual bool AddRefreshObserverExternal(nsARefreshObserver* aObserver,
1441 mozFlushType aFlushType);
1442 bool AddRefreshObserverInternal(nsARefreshObserver* aObserver,
1443 mozFlushType aFlushType);
1444 virtual bool RemoveRefreshObserverExternal(nsARefreshObserver* aObserver,
1445 mozFlushType aFlushType);
1446 bool RemoveRefreshObserverInternal(nsARefreshObserver* aObserver,
1447 mozFlushType aFlushType);
1448
1449 /**
1450 * Do computations necessary to determine if font size inflation is enabled.
1451 * This value is cached after computation, as the computation is somewhat
1452 * expensive.
1453 */
1454 void RecomputeFontSizeInflationEnabled();
1455
1456 public:
1457 bool AddRefreshObserver(nsARefreshObserver* aObserver,
1458 mozFlushType aFlushType) {
1459 #ifdef MOZILLA_INTERNAL_API
1460 return AddRefreshObserverInternal(aObserver, aFlushType);
1461 #else
1462 return AddRefreshObserverExternal(aObserver, aFlushType);
1463 #endif
1464 }
1465
1466 bool RemoveRefreshObserver(nsARefreshObserver* aObserver,
1467 mozFlushType aFlushType) {
1468 #ifdef MOZILLA_INTERNAL_API
1469 return RemoveRefreshObserverInternal(aObserver, aFlushType);
1470 #else
1471 return RemoveRefreshObserverExternal(aObserver, aFlushType);
1472 #endif
1473 }
1474
1475 virtual bool AddPostRefreshObserver(nsAPostRefreshObserver* aObserver);
1476 virtual bool RemovePostRefreshObserver(nsAPostRefreshObserver* aObserver);
1477
1478 /**
1479 * Initialize and shut down static variables.
1480 */
1481 static void InitializeStatics();
1482 static void ReleaseStatics();
1483
1484 // If a frame in the subtree rooted at aFrame is capturing the mouse then
1485 // clears that capture.
1486 static void ClearMouseCapture(nsIFrame* aFrame);
1487
1488 void SetScrollPositionClampingScrollPortSize(nscoord aWidth, nscoord aHeight);
1489 bool IsScrollPositionClampingScrollPortSizeSet() {
1490 return mScrollPositionClampingScrollPortSizeSet;
1491 }
1492 nsSize GetScrollPositionClampingScrollPortSize() {
1493 NS_ASSERTION(mScrollPositionClampingScrollPortSizeSet, "asking for scroll port when its not set?");
1494 return mScrollPositionClampingScrollPortSize;
1495 }
1496
1497 void SetContentDocumentFixedPositionMargins(const nsMargin& aMargins);
1498 const nsMargin& GetContentDocumentFixedPositionMargins() {
1499 return mContentDocumentFixedPositionMargins;
1500 }
1501
1502 virtual void WindowSizeMoveDone() = 0;
1503 virtual void SysColorChanged() = 0;
1504 virtual void ThemeChanged() = 0;
1505 virtual void BackingScaleFactorChanged() = 0;
1506
1507 nscoord MaxLineBoxWidth() {
1508 return mMaxLineBoxWidth;
1509 }
1510
1511 void SetMaxLineBoxWidth(nscoord aMaxLineBoxWidth);
1512
1513 /**
1514 * Returns whether or not there is a reflow on zoom event pending. A reflow
1515 * on zoom event is a change to the max line box width, followed by a reflow.
1516 * This subsequent reflow event should treat all frames as though they resized
1517 * horizontally (and thus reflow all their descendants), rather than marking
1518 * all frames dirty from the root. This is the way the pres shell indicates
1519 * that an hresize reflow should take place during reflow state construction.
1520 */
1521 bool IsReflowOnZoomPending() {
1522 return mReflowOnZoomPending;
1523 }
1524
1525 /**
1526 * Clear the flag indicating whether a reflow on zoom event is pending. This
1527 * is performed at the very end of DoReflow().
1528 */
1529 void ClearReflowOnZoomPending() {
1530 mReflowOnZoomPending = false;
1531 }
1532
1533 /**
1534 * Documents belonging to an invisible DocShell must not be painted ever.
1535 */
1536 bool IsNeverPainting() {
1537 return mIsNeverPainting;
1538 }
1539
1540 void SetNeverPainting(bool aNeverPainting) {
1541 mIsNeverPainting = aNeverPainting;
1542 }
1543
1544 protected:
1545 friend class nsRefreshDriver;
1546
1547 // IMPORTANT: The ownership implicit in the following member variables
1548 // has been explicitly checked. If you add any members to this class,
1549 // please make the ownership explicit (pinkerton, scc).
1550
1551 // These are the same Document and PresContext owned by the DocViewer.
1552 // we must share ownership.
1553 nsIDocument* mDocument; // [STRONG]
1554 nsPresContext* mPresContext; // [STRONG]
1555 nsStyleSet* mStyleSet; // [OWNS]
1556 nsCSSFrameConstructor* mFrameConstructor; // [OWNS]
1557 nsViewManager* mViewManager; // [WEAK] docViewer owns it so I don't have to
1558 nsPresArena mFrameArena;
1559 nsFrameSelection* mSelection;
1560 // Pointer into mFrameConstructor - this is purely so that FrameManager() and
1561 // GetRootFrame() can be inlined:
1562 nsFrameManagerBase* mFrameManager;
1563 mozilla::WeakPtr<nsDocShell> mForwardingContainer;
1564 nsRefreshDriver* mHiddenInvalidationObserverRefreshDriver;
1565 #ifdef ACCESSIBILITY
1566 mozilla::a11y::DocAccessible* mDocAccessible;
1567 #endif
1568
1569 #ifdef DEBUG
1570 nsIFrame* mDrawEventTargetFrame;
1571 // Ensure that every allocation from the PresArena is eventually freed.
1572 uint32_t mPresArenaAllocCount;
1573 #endif
1574
1575 // Count of the number of times this presshell has been painted to a window.
1576 uint64_t mPaintCount;
1577
1578 nsSize mScrollPositionClampingScrollPortSize;
1579
1580 // This margin is intended to be used when laying out fixed position children
1581 // on this PresShell's viewport frame. See the documentation of
1582 // nsIDOMWindowUtils.setContentDocumentFixedPositionMargins for details of
1583 // their use.
1584 nsMargin mContentDocumentFixedPositionMargins;
1585
1586 // A list of weak frames. This is a pointer to the last item in the list.
1587 nsWeakFrame* mWeakFrames;
1588
1589 // Most recent canvas background color.
1590 nscolor mCanvasBackgroundColor;
1591
1592 // Used to force allocation and rendering of proportionally more or
1593 // less pixels in the given dimension.
1594 float mXResolution;
1595 float mYResolution;
1596
1597 int16_t mSelectionFlags;
1598
1599 // Flags controlling how our document is rendered. These persist
1600 // between paints and so are tied with retained layer pixels.
1601 // PresShell flushes retained layers when the rendering state
1602 // changes in a way that prevents us from being able to (usefully)
1603 // re-use old pixels.
1604 RenderFlags mRenderFlags;
1605
1606 // Indicates that the whole document must be restyled. Changes to scoped
1607 // style sheets are recorded in mChangedScopeStyleRoots rather than here
1608 // in mStylesHaveChanged.
1609 bool mStylesHaveChanged : 1;
1610 bool mDidInitialize : 1;
1611 bool mIsDestroying : 1;
1612 bool mIsZombie : 1;
1613 bool mIsReflowing : 1;
1614
1615 // For all documents we initially lock down painting.
1616 bool mPaintingSuppressed : 1;
1617
1618 // Whether or not form controls should use nsITheme in this shell.
1619 bool mIsThemeSupportDisabled : 1;
1620
1621 bool mIsActive : 1;
1622 bool mFrozen : 1;
1623 bool mIsFirstPaint : 1;
1624 bool mObservesMutationsForPrint : 1;
1625
1626 // If true, we have a reflow scheduled. Guaranteed to be false if
1627 // mReflowContinueTimer is non-null.
1628 bool mReflowScheduled : 1;
1629
1630 bool mSuppressInterruptibleReflows : 1;
1631 bool mScrollPositionClampingScrollPortSizeSet : 1;
1632
1633 uint32_t mPresShellId;
1634
1635 // List of subtrees rooted at style scope roots that need to be restyled.
1636 // When a change to a scoped style sheet is made, we add the style scope
1637 // root to this array rather than setting mStylesHaveChanged = true, since
1638 // we know we don't need to restyle the whole document. However, if in the
1639 // same update block we have already had other changes that require
1640 // the whole document to be restyled (i.e., mStylesHaveChanged is already
1641 // true), then we don't bother adding the scope root here.
1642 nsAutoTArray<nsRefPtr<mozilla::dom::Element>,1> mChangedScopeStyleRoots;
1643
1644 static nsIContent* gKeyDownTarget;
1645
1646 // Cached font inflation values. This is done to prevent changing of font
1647 // inflation until a page is reloaded.
1648 uint32_t mFontSizeInflationEmPerLine;
1649 uint32_t mFontSizeInflationMinTwips;
1650 uint32_t mFontSizeInflationLineThreshold;
1651 bool mFontSizeInflationForceEnabled;
1652 bool mFontSizeInflationDisabledInMasterProcess;
1653 bool mFontSizeInflationEnabled;
1654 bool mPaintingIsFrozen;
1655
1656 // Dirty bit indicating that mFontSizeInflationEnabled needs to be recomputed.
1657 bool mFontSizeInflationEnabledIsDirty;
1658
1659 // Flag to indicate whether or not there is a reflow on zoom event pending.
1660 // See IsReflowOnZoomPending() for more information.
1661 bool mReflowOnZoomPending;
1662
1663 // The maximum width of a line box. Text on a single line that exceeds this
1664 // width will be wrapped. A value of 0 indicates that no limit is enforced.
1665 nscoord mMaxLineBoxWidth;
1666
1667 // If a document belongs to an invisible DocShell, this flag must be set
1668 // to true, so we can avoid any paint calls for widget related to this
1669 // presshell.
1670 bool mIsNeverPainting;
1671 };
1672
1673 NS_DEFINE_STATIC_IID_ACCESSOR(nsIPresShell, NS_IPRESSHELL_IID)
1674
1675 #endif /* nsIPresShell_h___ */

mercurial