Bug 846320 - Remove SimpleTest.expectAssertions in test_seek.html. r=dbaron
[gecko.git] / layout / base / nsPresShell.h
blob6ed0f45fbe5e3edc18e75b1af69da6b725bb377f
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * vim: set ts=2 sw=2 et tw=78:
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 * This Original Code has been modified by IBM Corporation.
8 * Modifications made by IBM described herein are
9 * Copyright (c) International Business Machines
10 * Corporation, 2000
12 * Modifications to Mozilla code or documentation
13 * identified per MPL Section 3.3
15 * Date Modified by Description of modification
16 * 05/03/2000 IBM Corp. Observer events for reflow states
19 /* a presentation of a document, part 2 */
21 #ifndef nsPresShell_h_
22 #define nsPresShell_h_
24 #include "nsIPresShell.h"
25 #include "nsStubDocumentObserver.h"
26 #include "nsISelectionController.h"
27 #include "nsIObserver.h"
28 #include "nsWeakReference.h"
29 #include "nsCRT.h"
30 #include "nsAutoPtr.h"
31 #include "nsIWidget.h"
32 #include "nsStyleSet.h"
33 #include "nsPresArena.h"
34 #include "nsFrameSelection.h"
35 #include "nsGUIEvent.h"
36 #include "nsContentUtils.h" // For AddScriptBlocker().
37 #include "nsRefreshDriver.h"
38 #include "mozilla/Attributes.h"
40 class nsRange;
41 class nsIDragService;
42 class nsCSSStyleSheet;
44 struct RangePaintInfo;
45 struct nsCallbackEventRequest;
46 #ifdef MOZ_REFLOW_PERF
47 class ReflowCountMgr;
48 #endif
50 class nsPresShellEventCB;
51 class nsAutoCauseReflowNotifier;
53 // 250ms. This is actually pref-controlled, but we use this value if we fail
54 // to get the pref for any reason.
55 #define PAINTLOCK_EVENT_DELAY 250
57 class PresShell : public nsIPresShell,
58 public nsStubDocumentObserver,
59 public nsISelectionController, public nsIObserver,
60 public nsSupportsWeakReference
62 public:
63 PresShell();
65 NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW
67 // nsISupports
68 NS_DECL_ISUPPORTS
70 // nsIPresShell
71 virtual NS_HIDDEN_(nsresult) Init(nsIDocument* aDocument,
72 nsPresContext* aPresContext,
73 nsViewManager* aViewManager,
74 nsStyleSet* aStyleSet,
75 nsCompatibility aCompatMode);
76 virtual NS_HIDDEN_(void) Destroy();
77 virtual NS_HIDDEN_(void) MakeZombie();
79 virtual NS_HIDDEN_(nsresult) SetPreferenceStyleRules(bool aForceReflow);
81 NS_IMETHOD GetSelection(SelectionType aType, nsISelection** aSelection);
82 virtual mozilla::Selection* GetCurrentSelection(SelectionType aType);
84 NS_IMETHOD SetDisplaySelection(int16_t aToggle);
85 NS_IMETHOD GetDisplaySelection(int16_t *aToggle);
86 NS_IMETHOD ScrollSelectionIntoView(SelectionType aType, SelectionRegion aRegion,
87 int16_t aFlags);
88 NS_IMETHOD RepaintSelection(SelectionType aType);
90 virtual NS_HIDDEN_(void) BeginObservingDocument();
91 virtual NS_HIDDEN_(void) EndObservingDocument();
92 virtual NS_HIDDEN_(nsresult) Initialize(nscoord aWidth, nscoord aHeight);
93 virtual NS_HIDDEN_(nsresult) ResizeReflow(nscoord aWidth, nscoord aHeight);
94 virtual NS_HIDDEN_(nsresult) ResizeReflowOverride(nscoord aWidth, nscoord aHeight);
95 virtual NS_HIDDEN_(void) StyleChangeReflow();
96 virtual NS_HIDDEN_(nsIPageSequenceFrame*) GetPageSequenceFrame() const;
97 virtual NS_HIDDEN_(nsIFrame*) GetRealPrimaryFrameFor(nsIContent* aContent) const;
99 virtual NS_HIDDEN_(nsIFrame*) GetPlaceholderFrameFor(nsIFrame* aFrame) const;
100 virtual NS_HIDDEN_(void) FrameNeedsReflow(nsIFrame *aFrame, IntrinsicDirty aIntrinsicDirty,
101 nsFrameState aBitToAdd);
102 virtual NS_HIDDEN_(void) FrameNeedsToContinueReflow(nsIFrame *aFrame);
103 virtual NS_HIDDEN_(void) CancelAllPendingReflows();
104 virtual NS_HIDDEN_(bool) IsSafeToFlush() const;
105 virtual NS_HIDDEN_(void) FlushPendingNotifications(mozFlushType aType);
106 virtual NS_HIDDEN_(void) FlushPendingNotifications(mozilla::ChangesToFlush aType);
109 * Recreates the frames for a node
111 virtual NS_HIDDEN_(nsresult) RecreateFramesFor(nsIContent* aContent);
114 * Post a callback that should be handled after reflow has finished.
116 virtual NS_HIDDEN_(nsresult) PostReflowCallback(nsIReflowCallback* aCallback);
117 virtual NS_HIDDEN_(void) CancelReflowCallback(nsIReflowCallback* aCallback);
119 virtual NS_HIDDEN_(void) ClearFrameRefs(nsIFrame* aFrame);
120 virtual NS_HIDDEN_(already_AddRefed<nsRenderingContext>) GetReferenceRenderingContext();
121 virtual NS_HIDDEN_(nsresult) GoToAnchor(const nsAString& aAnchorName, bool aScroll);
122 virtual NS_HIDDEN_(nsresult) ScrollToAnchor();
124 virtual NS_HIDDEN_(nsresult) ScrollContentIntoView(nsIContent* aContent,
125 ScrollAxis aVertical,
126 ScrollAxis aHorizontal,
127 uint32_t aFlags);
128 virtual bool ScrollFrameRectIntoView(nsIFrame* aFrame,
129 const nsRect& aRect,
130 ScrollAxis aVertical,
131 ScrollAxis aHorizontal,
132 uint32_t aFlags);
133 virtual nsRectVisibility GetRectVisibility(nsIFrame *aFrame,
134 const nsRect &aRect,
135 nscoord aMinTwips) const;
137 virtual NS_HIDDEN_(void) SetIgnoreFrameDestruction(bool aIgnore);
138 virtual NS_HIDDEN_(void) NotifyDestroyingFrame(nsIFrame* aFrame);
140 virtual NS_HIDDEN_(nsresult) CaptureHistoryState(nsILayoutHistoryState** aLayoutHistoryState);
142 virtual NS_HIDDEN_(void) UnsuppressPainting();
144 virtual nsresult GetAgentStyleSheets(nsCOMArray<nsIStyleSheet>& aSheets);
145 virtual nsresult SetAgentStyleSheets(const nsCOMArray<nsIStyleSheet>& aSheets);
147 virtual nsresult AddOverrideStyleSheet(nsIStyleSheet *aSheet);
148 virtual nsresult RemoveOverrideStyleSheet(nsIStyleSheet *aSheet);
150 virtual NS_HIDDEN_(nsresult) HandleEventWithTarget(nsEvent* aEvent, nsIFrame* aFrame,
151 nsIContent* aContent,
152 nsEventStatus* aStatus);
153 virtual NS_HIDDEN_(nsIFrame*) GetEventTargetFrame();
154 virtual NS_HIDDEN_(already_AddRefed<nsIContent>) GetEventTargetContent(nsEvent* aEvent);
157 virtual nsresult ReconstructFrames(void);
158 virtual void Freeze();
159 virtual void Thaw();
160 virtual void FireOrClearDelayedEvents(bool aFireEvents);
162 virtual NS_HIDDEN_(nsresult) RenderDocument(const nsRect& aRect, uint32_t aFlags,
163 nscolor aBackgroundColor,
164 gfxContext* aThebesContext);
166 virtual already_AddRefed<gfxASurface> RenderNode(nsIDOMNode* aNode,
167 nsIntRegion* aRegion,
168 nsIntPoint& aPoint,
169 nsIntRect* aScreenRect);
171 virtual already_AddRefed<gfxASurface> RenderSelection(nsISelection* aSelection,
172 nsIntPoint& aPoint,
173 nsIntRect* aScreenRect);
175 virtual already_AddRefed<nsPIDOMWindow> GetRootWindow();
177 virtual LayerManager* GetLayerManager();
179 virtual void SetIgnoreViewportScrolling(bool aIgnore);
181 virtual void SetDisplayPort(const nsRect& aDisplayPort);
183 virtual nsresult SetResolution(float aXResolution, float aYResolution);
185 //nsIViewObserver interface
187 virtual void Paint(nsView* aViewToPaint, const nsRegion& aDirtyRegion,
188 uint32_t aFlags);
189 virtual nsresult HandleEvent(nsIFrame* aFrame,
190 nsGUIEvent* aEvent,
191 bool aDontRetargetEvents,
192 nsEventStatus* aEventStatus);
193 virtual NS_HIDDEN_(nsresult) HandleDOMEventWithTarget(nsIContent* aTargetContent,
194 nsEvent* aEvent,
195 nsEventStatus* aStatus);
196 virtual NS_HIDDEN_(nsresult) HandleDOMEventWithTarget(nsIContent* aTargetContent,
197 nsIDOMEvent* aEvent,
198 nsEventStatus* aStatus);
199 virtual bool ShouldIgnoreInvalidation();
200 virtual void WillPaint();
201 virtual void WillPaintWindow();
202 virtual void DidPaintWindow();
203 virtual void ScheduleViewManagerFlush();
204 virtual void DispatchSynthMouseMove(nsGUIEvent *aEvent, bool aFlushOnHoverChange);
205 virtual void ClearMouseCaptureOnView(nsView* aView);
206 virtual bool IsVisible();
208 // caret handling
209 virtual NS_HIDDEN_(already_AddRefed<nsCaret>) GetCaret() const;
210 virtual NS_HIDDEN_(void) MaybeInvalidateCaretPosition();
211 NS_IMETHOD SetCaretEnabled(bool aInEnable);
212 NS_IMETHOD SetCaretReadOnly(bool aReadOnly);
213 NS_IMETHOD GetCaretEnabled(bool *aOutEnabled);
214 NS_IMETHOD SetCaretVisibilityDuringSelection(bool aVisibility);
215 NS_IMETHOD GetCaretVisible(bool *_retval);
216 virtual void SetCaret(nsCaret *aNewCaret);
217 virtual void RestoreCaret();
219 NS_IMETHOD SetSelectionFlags(int16_t aInEnable);
220 NS_IMETHOD GetSelectionFlags(int16_t *aOutEnable);
222 // nsISelectionController
224 NS_IMETHOD CharacterMove(bool aForward, bool aExtend);
225 NS_IMETHOD CharacterExtendForDelete();
226 NS_IMETHOD CharacterExtendForBackspace();
227 NS_IMETHOD WordMove(bool aForward, bool aExtend);
228 NS_IMETHOD WordExtendForDelete(bool aForward);
229 NS_IMETHOD LineMove(bool aForward, bool aExtend);
230 NS_IMETHOD IntraLineMove(bool aForward, bool aExtend);
231 NS_IMETHOD PageMove(bool aForward, bool aExtend);
232 NS_IMETHOD ScrollPage(bool aForward);
233 NS_IMETHOD ScrollLine(bool aForward);
234 NS_IMETHOD ScrollCharacter(bool aRight);
235 NS_IMETHOD CompleteScroll(bool aForward);
236 NS_IMETHOD CompleteMove(bool aForward, bool aExtend);
237 NS_IMETHOD SelectAll();
238 NS_IMETHOD CheckVisibility(nsIDOMNode *node, int16_t startOffset, int16_t EndOffset, bool *_retval);
239 virtual nsresult CheckVisibilityContent(nsIContent* aNode, int16_t aStartOffset,
240 int16_t aEndOffset, bool* aRetval);
242 // nsIDocumentObserver
243 NS_DECL_NSIDOCUMENTOBSERVER_BEGINUPDATE
244 NS_DECL_NSIDOCUMENTOBSERVER_ENDUPDATE
245 NS_DECL_NSIDOCUMENTOBSERVER_BEGINLOAD
246 NS_DECL_NSIDOCUMENTOBSERVER_ENDLOAD
247 NS_DECL_NSIDOCUMENTOBSERVER_CONTENTSTATECHANGED
248 NS_DECL_NSIDOCUMENTOBSERVER_DOCUMENTSTATESCHANGED
249 NS_DECL_NSIDOCUMENTOBSERVER_STYLESHEETADDED
250 NS_DECL_NSIDOCUMENTOBSERVER_STYLESHEETREMOVED
251 NS_DECL_NSIDOCUMENTOBSERVER_STYLESHEETAPPLICABLESTATECHANGED
252 NS_DECL_NSIDOCUMENTOBSERVER_STYLERULECHANGED
253 NS_DECL_NSIDOCUMENTOBSERVER_STYLERULEADDED
254 NS_DECL_NSIDOCUMENTOBSERVER_STYLERULEREMOVED
256 // nsIMutationObserver
257 NS_DECL_NSIMUTATIONOBSERVER_CHARACTERDATACHANGED
258 NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTEWILLCHANGE
259 NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTECHANGED
260 NS_DECL_NSIMUTATIONOBSERVER_CONTENTAPPENDED
261 NS_DECL_NSIMUTATIONOBSERVER_CONTENTINSERTED
262 NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED
264 NS_DECL_NSIOBSERVER
266 #ifdef MOZ_REFLOW_PERF
267 virtual NS_HIDDEN_(void) DumpReflows();
268 virtual NS_HIDDEN_(void) CountReflows(const char * aName, nsIFrame * aFrame);
269 virtual NS_HIDDEN_(void) PaintCount(const char * aName,
270 nsRenderingContext* aRenderingContext,
271 nsPresContext* aPresContext,
272 nsIFrame * aFrame,
273 const nsPoint& aOffset,
274 uint32_t aColor);
275 virtual NS_HIDDEN_(void) SetPaintFrameCount(bool aOn);
276 virtual bool IsPaintingFrameCounts();
277 #endif
279 #ifdef DEBUG
280 virtual void ListStyleContexts(nsIFrame *aRootFrame, FILE *out,
281 int32_t aIndent = 0);
283 virtual void ListStyleSheets(FILE *out, int32_t aIndent = 0);
284 virtual void VerifyStyleTree();
285 #endif
287 #ifdef PR_LOGGING
288 static PRLogModuleInfo* gLog;
289 #endif
291 virtual NS_HIDDEN_(void) DisableNonTestMouseEvents(bool aDisable);
293 virtual void UpdateCanvasBackground();
295 virtual void AddCanvasBackgroundColorItem(nsDisplayListBuilder& aBuilder,
296 nsDisplayList& aList,
297 nsIFrame* aFrame,
298 const nsRect& aBounds,
299 nscolor aBackstopColor,
300 uint32_t aFlags);
302 virtual void AddPrintPreviewBackgroundItem(nsDisplayListBuilder& aBuilder,
303 nsDisplayList& aList,
304 nsIFrame* aFrame,
305 const nsRect& aBounds);
307 virtual nscolor ComputeBackstopColor(nsView* aDisplayRoot);
309 virtual NS_HIDDEN_(nsresult) SetIsActive(bool aIsActive);
311 virtual bool GetIsViewportOverridden() { return mViewportOverridden; }
313 virtual bool IsLayoutFlushObserver()
315 return GetPresContext()->RefreshDriver()->
316 IsLayoutFlushObserver(this);
319 void SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf,
320 nsArenaMemoryStats *aArenaObjectsSize,
321 size_t *aPresShellSize,
322 size_t *aStyleSetsSize,
323 size_t *aTextRunsSize,
324 size_t *aPresContextSize);
325 size_t SizeOfTextRuns(nsMallocSizeOfFun aMallocSizeOf) const;
327 virtual void AddInvalidateHiddenPresShellObserver(nsRefreshDriver *aDriver);
330 // This data is stored as a content property (nsGkAtoms::scrolling) on
331 // mContentToScrollTo when we have a pending ScrollIntoView.
332 struct ScrollIntoViewData {
333 ScrollAxis mContentScrollVAxis;
334 ScrollAxis mContentScrollHAxis;
335 uint32_t mContentToScrollToFlags;
338 virtual void ScheduleImageVisibilityUpdate();
340 virtual void RebuildImageVisibility(const nsDisplayList& aList);
342 virtual void EnsureImageInVisibleList(nsIImageLoadingContent* aImage);
344 protected:
345 virtual ~PresShell();
347 void HandlePostedReflowCallbacks(bool aInterruptible);
348 void CancelPostedReflowCallbacks();
350 void UnsuppressAndInvalidate();
352 void WillCauseReflow() {
353 nsContentUtils::AddScriptBlocker();
354 ++mChangeNestCount;
356 nsresult DidCauseReflow();
357 friend class nsAutoCauseReflowNotifier;
359 bool TouchesAreEqual(nsIDOMTouch *aTouch1, nsIDOMTouch *aTouch2);
360 void DispatchTouchEvent(nsEvent *aEvent,
361 nsEventStatus* aStatus,
362 nsPresShellEventCB* aEventCB,
363 bool aTouchIsNew);
365 void WillDoReflow();
366 void DidDoReflow(bool aInterruptible);
367 // ProcessReflowCommands returns whether we processed all our dirty roots
368 // without interruptions.
369 bool ProcessReflowCommands(bool aInterruptible);
370 // MaybeScheduleReflow checks if posting a reflow is needed, then checks if
371 // the last reflow was interrupted. In the interrupted case ScheduleReflow is
372 // called off a timer, otherwise it is called directly.
373 void MaybeScheduleReflow();
374 // Actually schedules a reflow. This should only be called by
375 // MaybeScheduleReflow and the reflow timer ScheduleReflowOffTimer
376 // sets up.
377 void ScheduleReflow();
379 // Reflow regardless of whether the override bit has been set.
380 nsresult ResizeReflowIgnoreOverride(nscoord aWidth, nscoord aHeight);
382 // DoReflow returns whether the reflow finished without interruption
383 bool DoReflow(nsIFrame* aFrame, bool aInterruptible);
384 #ifdef DEBUG
385 void DoVerifyReflow();
386 void VerifyHasDirtyRootAncestor(nsIFrame* aFrame);
387 #endif
389 // Helper for ScrollContentIntoView
390 void DoScrollContentIntoView();
393 * Initialize cached font inflation preference values.
395 * @see nsLayoutUtils::sFontSizeInflationEmPerLine
396 * @see nsLayoutUtils::sFontSizeInflationMinTwips
397 * @see nsLayoutUtils::sFontSizeInflationLineThreshold
399 void SetupFontInflation();
401 friend struct AutoRenderingStateSaveRestore;
402 friend struct RenderingState;
404 struct RenderingState {
405 RenderingState(PresShell* aPresShell)
406 : mXResolution(aPresShell->mXResolution)
407 , mYResolution(aPresShell->mYResolution)
408 , mRenderFlags(aPresShell->mRenderFlags)
410 float mXResolution;
411 float mYResolution;
412 RenderFlags mRenderFlags;
415 struct AutoSaveRestoreRenderingState {
416 AutoSaveRestoreRenderingState(PresShell* aPresShell)
417 : mPresShell(aPresShell)
418 , mOldState(aPresShell)
421 ~AutoSaveRestoreRenderingState()
423 mPresShell->mRenderFlags = mOldState.mRenderFlags;
424 mPresShell->mXResolution = mOldState.mXResolution;
425 mPresShell->mYResolution = mOldState.mYResolution;
428 PresShell* mPresShell;
429 RenderingState mOldState;
431 static RenderFlags ChangeFlag(RenderFlags aFlags, bool aOnOff,
432 eRenderFlag aFlag)
434 return aOnOff ? (aFlags | aFlag) : (aFlag & ~aFlag);
438 void SetRenderingState(const RenderingState& aState);
440 friend class nsPresShellEventCB;
442 bool mCaretEnabled;
443 #ifdef DEBUG
444 nsStyleSet* CloneStyleSet(nsStyleSet* aSet);
445 bool VerifyIncrementalReflow();
446 bool mInVerifyReflow;
447 void ShowEventTargetDebug();
448 #endif
450 void RecordStyleSheetChange(nsIStyleSheet* aStyleSheet);
453 * methods that manage rules that are used to implement the associated preferences
454 * - initially created for bugs 31816, 20760, 22963
456 nsresult ClearPreferenceStyleRules(void);
457 nsresult CreatePreferenceStyleSheet(void);
458 nsresult SetPrefLinkRules(void);
459 nsresult SetPrefFocusRules(void);
460 nsresult SetPrefNoScriptRule();
461 nsresult SetPrefNoFramesRule(void);
463 // methods for painting a range to an offscreen buffer
465 // given a display list, clip the items within the list to
466 // the range
467 nsRect ClipListToRange(nsDisplayListBuilder *aBuilder,
468 nsDisplayList* aList,
469 nsRange* aRange);
471 // create a RangePaintInfo for the range aRange containing the
472 // display list needed to paint the range to a surface
473 RangePaintInfo* CreateRangePaintInfo(nsIDOMRange* aRange,
474 nsRect& aSurfaceRect,
475 bool aForPrimarySelection);
478 * Paint the items to a new surface and return it.
480 * aSelection - selection being painted, if any
481 * aRegion - clip region, if any
482 * aArea - area that the surface occupies, relative to the root frame
483 * aPoint - reference point, typically the mouse position
484 * aScreenRect - [out] set to the area of the screen the painted area should
485 * be displayed at
487 already_AddRefed<gfxASurface>
488 PaintRangePaintInfo(nsTArray<nsAutoPtr<RangePaintInfo> >* aItems,
489 nsISelection* aSelection,
490 nsIntRegion* aRegion,
491 nsRect aArea,
492 nsIntPoint& aPoint,
493 nsIntRect* aScreenRect);
496 * Methods to handle changes to user and UA sheet lists that we get
497 * notified about.
499 void AddUserSheet(nsISupports* aSheet);
500 void AddAgentSheet(nsISupports* aSheet);
501 void AddAuthorSheet(nsISupports* aSheet);
502 void RemoveSheet(nsStyleSet::sheetType aType, nsISupports* aSheet);
504 // Hide a view if it is a popup
505 void HideViewIfPopup(nsView* aView);
507 // Utility method to restore the root scrollframe state
508 void RestoreRootScrollPosition();
510 void MaybeReleaseCapturingContent()
512 nsRefPtr<nsFrameSelection> frameSelection = FrameSelection();
513 if (frameSelection) {
514 frameSelection->SetMouseDownState(false);
516 if (gCaptureInfo.mContent &&
517 gCaptureInfo.mContent->OwnerDoc() == mDocument) {
518 SetCapturingContent(nullptr, 0);
522 nsresult HandleRetargetedEvent(nsEvent* aEvent, nsEventStatus* aStatus, nsIContent* aTarget)
524 PushCurrentEventInfo(nullptr, nullptr);
525 mCurrentEventContent = aTarget;
526 nsresult rv = NS_OK;
527 if (GetCurrentEventFrame()) {
528 rv = HandleEventInternal(aEvent, aStatus);
530 PopCurrentEventInfo();
531 return rv;
534 class nsDelayedEvent
536 public:
537 virtual ~nsDelayedEvent() {};
538 virtual void Dispatch(PresShell* aShell) {}
541 class nsDelayedInputEvent : public nsDelayedEvent
543 public:
544 virtual void Dispatch(PresShell* aShell)
546 if (mEvent && mEvent->widget) {
547 nsCOMPtr<nsIWidget> w = mEvent->widget;
548 nsEventStatus status;
549 w->DispatchEvent(mEvent, status);
553 protected:
554 void Init(nsInputEvent* aEvent)
556 mEvent->time = aEvent->time;
557 mEvent->refPoint = aEvent->refPoint;
558 mEvent->modifiers = aEvent->modifiers;
561 nsDelayedInputEvent()
562 : nsDelayedEvent(), mEvent(nullptr) {}
564 nsInputEvent* mEvent;
567 class nsDelayedMouseEvent : public nsDelayedInputEvent
569 public:
570 nsDelayedMouseEvent(nsMouseEvent* aEvent) : nsDelayedInputEvent()
572 mEvent = new nsMouseEvent(aEvent->mFlags.mIsTrusted,
573 aEvent->message,
574 aEvent->widget,
575 aEvent->reason,
576 aEvent->context);
577 Init(aEvent);
578 static_cast<nsMouseEvent*>(mEvent)->clickCount = aEvent->clickCount;
581 virtual ~nsDelayedMouseEvent()
583 delete static_cast<nsMouseEvent*>(mEvent);
587 class nsDelayedKeyEvent : public nsDelayedInputEvent
589 public:
590 nsDelayedKeyEvent(nsKeyEvent* aEvent) : nsDelayedInputEvent()
592 mEvent = new nsKeyEvent(aEvent->mFlags.mIsTrusted,
593 aEvent->message,
594 aEvent->widget);
595 Init(aEvent);
596 static_cast<nsKeyEvent*>(mEvent)->keyCode = aEvent->keyCode;
597 static_cast<nsKeyEvent*>(mEvent)->charCode = aEvent->charCode;
598 static_cast<nsKeyEvent*>(mEvent)->alternativeCharCodes =
599 aEvent->alternativeCharCodes;
600 static_cast<nsKeyEvent*>(mEvent)->isChar = aEvent->isChar;
603 virtual ~nsDelayedKeyEvent()
605 delete static_cast<nsKeyEvent*>(mEvent);
609 // Check if aEvent is a mouse event and record the mouse location for later
610 // synth mouse moves.
611 void RecordMouseLocation(nsGUIEvent* aEvent);
612 class nsSynthMouseMoveEvent MOZ_FINAL : public nsARefreshObserver {
613 public:
614 nsSynthMouseMoveEvent(PresShell* aPresShell, bool aFromScroll)
615 : mPresShell(aPresShell), mFromScroll(aFromScroll) {
616 NS_ASSERTION(mPresShell, "null parameter");
618 ~nsSynthMouseMoveEvent() {
619 Revoke();
622 NS_INLINE_DECL_REFCOUNTING(nsSynthMouseMoveEvent)
624 void Revoke() {
625 if (mPresShell) {
626 mPresShell->GetPresContext()->RefreshDriver()->
627 RemoveRefreshObserver(this, Flush_Display);
628 mPresShell = nullptr;
631 virtual void WillRefresh(mozilla::TimeStamp aTime) MOZ_OVERRIDE {
632 if (mPresShell)
633 mPresShell->ProcessSynthMouseMoveEvent(mFromScroll);
635 private:
636 PresShell* mPresShell;
637 bool mFromScroll;
639 void ProcessSynthMouseMoveEvent(bool aFromScroll);
641 void QueryIsActive();
642 nsresult UpdateImageLockingState();
644 #ifdef ANDROID
645 nsIDocument* GetTouchEventTargetDocument();
646 #endif
647 bool InZombieDocument(nsIContent *aContent);
648 already_AddRefed<nsIPresShell> GetParentPresShell();
649 nsIFrame* GetCurrentEventFrame();
650 nsresult RetargetEventToParent(nsGUIEvent* aEvent,
651 nsEventStatus* aEventStatus);
652 void PushCurrentEventInfo(nsIFrame* aFrame, nsIContent* aContent);
653 void PopCurrentEventInfo();
654 nsresult HandleEventInternal(nsEvent* aEvent, nsEventStatus *aStatus);
655 nsresult HandlePositionedEvent(nsIFrame* aTargetFrame,
656 nsGUIEvent* aEvent,
657 nsEventStatus* aEventStatus);
658 // This returns the focused DOM window under our top level window.
659 // I.e., when we are deactive, this returns the *last* focused DOM window.
660 already_AddRefed<nsPIDOMWindow> GetFocusedDOMWindowInOurWindow();
663 * This and the next two helper methods are used to target and position the
664 * context menu when the keyboard shortcut is used to open it.
666 * If another menu is open, the context menu is opened relative to the
667 * active menuitem within the menu, or the menu itself if no item is active.
668 * Otherwise, if the caret is visible, the menu is opened near the caret.
669 * Otherwise, if a selectable list such as a listbox is focused, the
670 * current item within the menu is opened relative to this item.
671 * Otherwise, the context menu is opened at the topleft corner of the
672 * view.
674 * Returns true if the context menu event should fire and false if it should
675 * not.
677 bool AdjustContextMenuKeyEvent(nsMouseEvent* aEvent);
680 bool PrepareToUseCaretPosition(nsIWidget* aEventWidget, nsIntPoint& aTargetPt);
682 // Get the selected item and coordinates in device pixels relative to root
683 // document's root view for element, first ensuring the element is onscreen
684 void GetCurrentItemAndPositionForElement(nsIDOMElement *aCurrentEl,
685 nsIContent **aTargetToUse,
686 nsIntPoint& aTargetPt,
687 nsIWidget *aRootWidget);
689 void FireResizeEvent();
690 void FireBeforeResizeEvent();
691 static void AsyncResizeEventCallback(nsITimer* aTimer, void* aPresShell);
693 virtual void SynthesizeMouseMove(bool aFromScroll);
695 PresShell* GetRootPresShell();
697 nscolor GetDefaultBackgroundColorToDraw();
699 // The callback for the mPaintSuppressionTimer timer.
700 static void sPaintSuppressionCallback(nsITimer* aTimer, void* aPresShell);
702 // The callback for the mReflowContinueTimer timer.
703 static void sReflowContinueCallback(nsITimer* aTimer, void* aPresShell);
704 bool ScheduleReflowOffTimer();
706 // Widget notificiations
707 virtual void WindowSizeMoveDone();
708 virtual void SysColorChanged() { mPresContext->SysColorChanged(); }
709 virtual void ThemeChanged() { mPresContext->ThemeChanged(); }
710 virtual void BackingScaleFactorChanged() { mPresContext->UIResolutionChanged(); }
712 void UpdateImageVisibility();
714 nsRevocableEventPtr<nsRunnableMethod<PresShell> > mUpdateImageVisibilityEvent;
716 void ClearVisibleImagesList();
717 static void ClearImageVisibilityVisited(nsView* aView, bool aClear);
718 static void MarkImagesInListVisible(const nsDisplayList& aList);
720 // A list of images that are visible or almost visible.
721 nsTArray< nsCOMPtr<nsIImageLoadingContent > > mVisibleImages;
723 #ifdef DEBUG
724 // The reflow root under which we're currently reflowing. Null when
725 // not in reflow.
726 nsIFrame* mCurrentReflowRoot;
727 uint32_t mUpdateCount;
728 #endif
730 #ifdef MOZ_REFLOW_PERF
731 ReflowCountMgr* mReflowCountMgr;
732 #endif
734 // This is used for synthetic mouse events that are sent when what is under
735 // the mouse pointer may have changed without the mouse moving (eg scrolling,
736 // change to the document contents).
737 // It is set only on a presshell for a root document, this value represents
738 // the last observed location of the mouse relative to that root document. It
739 // is set to (NS_UNCONSTRAINEDSIZE, NS_UNCONSTRAINEDSIZE) if the mouse isn't
740 // over our window or there is no last observed mouse location for some
741 // reason.
742 nsPoint mMouseLocation;
744 // mStyleSet owns it but we maintain a ref, may be null
745 nsRefPtr<nsCSSStyleSheet> mPrefStyleSheet;
747 // Set of frames that we should mark with NS_FRAME_HAS_DIRTY_CHILDREN after
748 // we finish reflowing mCurrentReflowRoot.
749 nsTHashtable<nsPtrHashKey<nsIFrame> > mFramesToDirty;
751 // Reflow roots that need to be reflowed.
752 nsTArray<nsIFrame*> mDirtyRoots;
754 nsTArray<nsAutoPtr<nsDelayedEvent> > mDelayedEvents;
755 nsRevocableEventPtr<nsRunnableMethod<PresShell> > mResizeEvent;
756 nsCOMPtr<nsITimer> mAsyncResizeEventTimer;
757 nsIFrame* mCurrentEventFrame;
758 nsCOMPtr<nsIContent> mCurrentEventContent;
759 nsTArray<nsIFrame*> mCurrentEventFrameStack;
760 nsCOMArray<nsIContent> mCurrentEventContentStack;
761 nsRevocableEventPtr<nsSynthMouseMoveEvent> mSynthMouseMoveEvent;
762 nsCOMPtr<nsIContent> mLastAnchorScrolledTo;
763 nsRefPtr<nsCaret> mCaret;
764 nsRefPtr<nsCaret> mOriginalCaret;
765 nsCallbackEventRequest* mFirstCallbackEventRequest;
766 nsCallbackEventRequest* mLastCallbackEventRequest;
768 // This timer controls painting suppression. Until it fires
769 // or all frames are constructed, we won't paint anything but
770 // our <body> background and scrollbars.
771 nsCOMPtr<nsITimer> mPaintSuppressionTimer;
773 // At least on Win32 and Mac after interupting a reflow we need to post
774 // the resume reflow event off a timer to avoid event starvation because
775 // posted messages are processed before other messages when the modal
776 // moving/sizing loop is running, see bug 491700 for details.
777 nsCOMPtr<nsITimer> mReflowContinueTimer;
779 // Information needed to properly handle scrolling content into view if the
780 // pre-scroll reflow flush can be interrupted. mContentToScrollTo is
781 // non-null between the initial scroll attempt and the first time we finish
782 // processing all our dirty roots. mContentToScrollTo has a content property
783 // storing the details for the scroll operation, see ScrollIntoViewData above.
784 nsCOMPtr<nsIContent> mContentToScrollTo;
786 nscoord mLastAnchorScrollPositionY;
788 // This is used to protect ourselves from triggering reflow while in the
789 // middle of frame construction and the like... it really shouldn't be
790 // needed, one hopes, but it is for now.
791 uint16_t mChangeNestCount;
793 bool mDocumentLoading : 1;
794 bool mIgnoreFrameDestruction : 1;
795 bool mHaveShutDown : 1;
796 bool mViewportOverridden : 1;
797 bool mLastRootReflowHadUnconstrainedHeight : 1;
798 bool mNoDelayedMouseEvents : 1;
799 bool mNoDelayedKeyEvents : 1;
801 // We've been disconnected from the document. We will refuse to paint the
802 // document until either our timer fires or all frames are constructed.
803 bool mIsDocumentGone : 1;
805 // Indicates that it is safe to unlock painting once all pending reflows
806 // have been processed.
807 bool mShouldUnsuppressPainting : 1;
809 bool mAsyncResizeTimerIsActive : 1;
810 bool mInResize : 1;
812 bool mImageVisibilityVisited : 1;
814 static bool sDisableNonTestMouseEvents;
817 #endif /* !defined(nsPresShell_h_) */