1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/layout/base/nsPresShell.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,821 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- 1.5 + * vim: set ts=2 sw=2 et tw=78: 1.6 + * This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. 1.9 + * 1.10 + * This Original Code has been modified by IBM Corporation. 1.11 + * Modifications made by IBM described herein are 1.12 + * Copyright (c) International Business Machines 1.13 + * Corporation, 2000 1.14 + * 1.15 + * Modifications to Mozilla code or documentation 1.16 + * identified per MPL Section 3.3 1.17 + * 1.18 + * Date Modified by Description of modification 1.19 + * 05/03/2000 IBM Corp. Observer events for reflow states 1.20 + */ 1.21 + 1.22 +/* a presentation of a document, part 2 */ 1.23 + 1.24 +#ifndef nsPresShell_h_ 1.25 +#define nsPresShell_h_ 1.26 + 1.27 +#include "nsIPresShell.h" 1.28 +#include "nsStubDocumentObserver.h" 1.29 +#include "nsISelectionController.h" 1.30 +#include "nsIObserver.h" 1.31 +#include "nsWeakReference.h" 1.32 +#include "nsCRT.h" 1.33 +#include "nsAutoPtr.h" 1.34 +#include "nsIWidget.h" 1.35 +#include "nsStyleSet.h" 1.36 +#include "nsFrameSelection.h" 1.37 +#include "nsContentUtils.h" // For AddScriptBlocker(). 1.38 +#include "nsRefreshDriver.h" 1.39 +#include "mozilla/Attributes.h" 1.40 +#include "mozilla/EventForwards.h" 1.41 +#include "mozilla/MemoryReporting.h" 1.42 + 1.43 +class nsRange; 1.44 +class nsIDragService; 1.45 +class nsCSSStyleSheet; 1.46 + 1.47 +struct RangePaintInfo; 1.48 +struct nsCallbackEventRequest; 1.49 +#ifdef MOZ_REFLOW_PERF 1.50 +class ReflowCountMgr; 1.51 +#endif 1.52 + 1.53 +class nsPresShellEventCB; 1.54 +class nsAutoCauseReflowNotifier; 1.55 + 1.56 +// 250ms. This is actually pref-controlled, but we use this value if we fail 1.57 +// to get the pref for any reason. 1.58 +#define PAINTLOCK_EVENT_DELAY 250 1.59 + 1.60 +class PresShell : public nsIPresShell, 1.61 + public nsStubDocumentObserver, 1.62 + public nsISelectionController, public nsIObserver, 1.63 + public nsSupportsWeakReference 1.64 +{ 1.65 +public: 1.66 + PresShell(); 1.67 + 1.68 + NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW 1.69 + 1.70 + // nsISupports 1.71 + NS_DECL_ISUPPORTS 1.72 + 1.73 + void Init(nsIDocument* aDocument, nsPresContext* aPresContext, 1.74 + nsViewManager* aViewManager, nsStyleSet* aStyleSet, 1.75 + nsCompatibility aCompatMode); 1.76 + virtual NS_HIDDEN_(void) Destroy() MOZ_OVERRIDE; 1.77 + virtual NS_HIDDEN_(void) MakeZombie() MOZ_OVERRIDE; 1.78 + 1.79 + virtual NS_HIDDEN_(nsresult) SetPreferenceStyleRules(bool aForceReflow) MOZ_OVERRIDE; 1.80 + 1.81 + NS_IMETHOD GetSelection(SelectionType aType, nsISelection** aSelection); 1.82 + virtual mozilla::dom::Selection* GetCurrentSelection(SelectionType aType) MOZ_OVERRIDE; 1.83 + 1.84 + NS_IMETHOD SetDisplaySelection(int16_t aToggle) MOZ_OVERRIDE; 1.85 + NS_IMETHOD GetDisplaySelection(int16_t *aToggle) MOZ_OVERRIDE; 1.86 + NS_IMETHOD ScrollSelectionIntoView(SelectionType aType, SelectionRegion aRegion, 1.87 + int16_t aFlags) MOZ_OVERRIDE; 1.88 + NS_IMETHOD RepaintSelection(SelectionType aType) MOZ_OVERRIDE; 1.89 + 1.90 + virtual NS_HIDDEN_(void) BeginObservingDocument() MOZ_OVERRIDE; 1.91 + virtual NS_HIDDEN_(void) EndObservingDocument() MOZ_OVERRIDE; 1.92 + virtual NS_HIDDEN_(nsresult) Initialize(nscoord aWidth, nscoord aHeight) MOZ_OVERRIDE; 1.93 + virtual NS_HIDDEN_(nsresult) ResizeReflow(nscoord aWidth, nscoord aHeight) MOZ_OVERRIDE; 1.94 + virtual NS_HIDDEN_(nsresult) ResizeReflowOverride(nscoord aWidth, nscoord aHeight) MOZ_OVERRIDE; 1.95 + virtual NS_HIDDEN_(nsIPageSequenceFrame*) GetPageSequenceFrame() const MOZ_OVERRIDE; 1.96 + virtual NS_HIDDEN_(nsIFrame*) GetRealPrimaryFrameFor(nsIContent* aContent) const MOZ_OVERRIDE; 1.97 + 1.98 + virtual NS_HIDDEN_(nsIFrame*) GetPlaceholderFrameFor(nsIFrame* aFrame) const MOZ_OVERRIDE; 1.99 + virtual NS_HIDDEN_(void) FrameNeedsReflow(nsIFrame *aFrame, IntrinsicDirty aIntrinsicDirty, 1.100 + nsFrameState aBitToAdd) MOZ_OVERRIDE; 1.101 + virtual NS_HIDDEN_(void) FrameNeedsToContinueReflow(nsIFrame *aFrame) MOZ_OVERRIDE; 1.102 + virtual NS_HIDDEN_(void) CancelAllPendingReflows() MOZ_OVERRIDE; 1.103 + virtual NS_HIDDEN_(bool) IsSafeToFlush() const MOZ_OVERRIDE; 1.104 + virtual NS_HIDDEN_(void) FlushPendingNotifications(mozFlushType aType) MOZ_OVERRIDE; 1.105 + virtual NS_HIDDEN_(void) FlushPendingNotifications(mozilla::ChangesToFlush aType) MOZ_OVERRIDE; 1.106 + 1.107 + /** 1.108 + * Recreates the frames for a node 1.109 + */ 1.110 + virtual NS_HIDDEN_(nsresult) RecreateFramesFor(nsIContent* aContent) MOZ_OVERRIDE; 1.111 + 1.112 + /** 1.113 + * Post a callback that should be handled after reflow has finished. 1.114 + */ 1.115 + virtual NS_HIDDEN_(nsresult) PostReflowCallback(nsIReflowCallback* aCallback) MOZ_OVERRIDE; 1.116 + virtual NS_HIDDEN_(void) CancelReflowCallback(nsIReflowCallback* aCallback) MOZ_OVERRIDE; 1.117 + 1.118 + virtual NS_HIDDEN_(void) ClearFrameRefs(nsIFrame* aFrame) MOZ_OVERRIDE; 1.119 + virtual NS_HIDDEN_(already_AddRefed<nsRenderingContext>) CreateReferenceRenderingContext(); 1.120 + virtual NS_HIDDEN_(nsresult) GoToAnchor(const nsAString& aAnchorName, bool aScroll) MOZ_OVERRIDE; 1.121 + virtual NS_HIDDEN_(nsresult) ScrollToAnchor() MOZ_OVERRIDE; 1.122 + 1.123 + virtual NS_HIDDEN_(nsresult) ScrollContentIntoView(nsIContent* aContent, 1.124 + ScrollAxis aVertical, 1.125 + ScrollAxis aHorizontal, 1.126 + uint32_t aFlags) MOZ_OVERRIDE; 1.127 + virtual bool ScrollFrameRectIntoView(nsIFrame* aFrame, 1.128 + const nsRect& aRect, 1.129 + ScrollAxis aVertical, 1.130 + ScrollAxis aHorizontal, 1.131 + uint32_t aFlags) MOZ_OVERRIDE; 1.132 + virtual nsRectVisibility GetRectVisibility(nsIFrame *aFrame, 1.133 + const nsRect &aRect, 1.134 + nscoord aMinTwips) const MOZ_OVERRIDE; 1.135 + 1.136 + virtual NS_HIDDEN_(void) SetIgnoreFrameDestruction(bool aIgnore) MOZ_OVERRIDE; 1.137 + virtual NS_HIDDEN_(void) NotifyDestroyingFrame(nsIFrame* aFrame) MOZ_OVERRIDE; 1.138 + 1.139 + virtual NS_HIDDEN_(nsresult) CaptureHistoryState(nsILayoutHistoryState** aLayoutHistoryState) MOZ_OVERRIDE; 1.140 + 1.141 + virtual NS_HIDDEN_(void) UnsuppressPainting() MOZ_OVERRIDE; 1.142 + 1.143 + virtual nsresult GetAgentStyleSheets(nsCOMArray<nsIStyleSheet>& aSheets) MOZ_OVERRIDE; 1.144 + virtual nsresult SetAgentStyleSheets(const nsCOMArray<nsIStyleSheet>& aSheets) MOZ_OVERRIDE; 1.145 + 1.146 + virtual nsresult AddOverrideStyleSheet(nsIStyleSheet *aSheet) MOZ_OVERRIDE; 1.147 + virtual nsresult RemoveOverrideStyleSheet(nsIStyleSheet *aSheet) MOZ_OVERRIDE; 1.148 + 1.149 + virtual NS_HIDDEN_(nsresult) HandleEventWithTarget( 1.150 + mozilla::WidgetEvent* aEvent, 1.151 + nsIFrame* aFrame, 1.152 + nsIContent* aContent, 1.153 + nsEventStatus* aStatus) MOZ_OVERRIDE; 1.154 + virtual NS_HIDDEN_(nsIFrame*) GetEventTargetFrame() MOZ_OVERRIDE; 1.155 + virtual NS_HIDDEN_(already_AddRefed<nsIContent>) GetEventTargetContent( 1.156 + mozilla::WidgetEvent* aEvent) MOZ_OVERRIDE; 1.157 + 1.158 + 1.159 + virtual nsresult ReconstructFrames(void) MOZ_OVERRIDE; 1.160 + virtual void Freeze() MOZ_OVERRIDE; 1.161 + virtual void Thaw() MOZ_OVERRIDE; 1.162 + virtual void FireOrClearDelayedEvents(bool aFireEvents) MOZ_OVERRIDE; 1.163 + 1.164 + virtual NS_HIDDEN_(nsresult) RenderDocument(const nsRect& aRect, uint32_t aFlags, 1.165 + nscolor aBackgroundColor, 1.166 + gfxContext* aThebesContext) MOZ_OVERRIDE; 1.167 + 1.168 + virtual mozilla::TemporaryRef<SourceSurface> 1.169 + RenderNode(nsIDOMNode* aNode, 1.170 + nsIntRegion* aRegion, 1.171 + nsIntPoint& aPoint, 1.172 + nsIntRect* aScreenRect) MOZ_OVERRIDE; 1.173 + 1.174 + virtual mozilla::TemporaryRef<SourceSurface> 1.175 + RenderSelection(nsISelection* aSelection, 1.176 + nsIntPoint& aPoint, 1.177 + nsIntRect* aScreenRect) MOZ_OVERRIDE; 1.178 + 1.179 + virtual already_AddRefed<nsPIDOMWindow> GetRootWindow() MOZ_OVERRIDE; 1.180 + 1.181 + virtual LayerManager* GetLayerManager() MOZ_OVERRIDE; 1.182 + 1.183 + virtual void SetIgnoreViewportScrolling(bool aIgnore) MOZ_OVERRIDE; 1.184 + 1.185 + virtual nsresult SetResolution(float aXResolution, float aYResolution) MOZ_OVERRIDE; 1.186 + virtual gfxSize GetCumulativeResolution() MOZ_OVERRIDE; 1.187 + 1.188 + //nsIViewObserver interface 1.189 + 1.190 + virtual void Paint(nsView* aViewToPaint, const nsRegion& aDirtyRegion, 1.191 + uint32_t aFlags) MOZ_OVERRIDE; 1.192 + virtual nsresult HandleEvent(nsIFrame* aFrame, 1.193 + mozilla::WidgetGUIEvent* aEvent, 1.194 + bool aDontRetargetEvents, 1.195 + nsEventStatus* aEventStatus) MOZ_OVERRIDE; 1.196 + virtual NS_HIDDEN_(nsresult) HandleDOMEventWithTarget( 1.197 + nsIContent* aTargetContent, 1.198 + mozilla::WidgetEvent* aEvent, 1.199 + nsEventStatus* aStatus) MOZ_OVERRIDE; 1.200 + virtual NS_HIDDEN_(nsresult) HandleDOMEventWithTarget(nsIContent* aTargetContent, 1.201 + nsIDOMEvent* aEvent, 1.202 + nsEventStatus* aStatus) MOZ_OVERRIDE; 1.203 + virtual bool ShouldIgnoreInvalidation() MOZ_OVERRIDE; 1.204 + virtual void WillPaint() MOZ_OVERRIDE; 1.205 + virtual void WillPaintWindow() MOZ_OVERRIDE; 1.206 + virtual void DidPaintWindow() MOZ_OVERRIDE; 1.207 + virtual void ScheduleViewManagerFlush(PaintType aType = PAINT_DEFAULT) MOZ_OVERRIDE; 1.208 + virtual void DispatchSynthMouseMove(mozilla::WidgetGUIEvent* aEvent, 1.209 + bool aFlushOnHoverChange) MOZ_OVERRIDE; 1.210 + virtual void ClearMouseCaptureOnView(nsView* aView) MOZ_OVERRIDE; 1.211 + virtual bool IsVisible() MOZ_OVERRIDE; 1.212 + 1.213 + // caret handling 1.214 + virtual NS_HIDDEN_(already_AddRefed<nsCaret>) GetCaret() const MOZ_OVERRIDE; 1.215 + virtual NS_HIDDEN_(void) MaybeInvalidateCaretPosition() MOZ_OVERRIDE; 1.216 + NS_IMETHOD SetCaretEnabled(bool aInEnable) MOZ_OVERRIDE; 1.217 + NS_IMETHOD SetCaretReadOnly(bool aReadOnly) MOZ_OVERRIDE; 1.218 + NS_IMETHOD GetCaretEnabled(bool *aOutEnabled) MOZ_OVERRIDE; 1.219 + NS_IMETHOD SetCaretVisibilityDuringSelection(bool aVisibility) MOZ_OVERRIDE; 1.220 + NS_IMETHOD GetCaretVisible(bool *_retval) MOZ_OVERRIDE; 1.221 + virtual void SetCaret(nsCaret *aNewCaret) MOZ_OVERRIDE; 1.222 + virtual void RestoreCaret() MOZ_OVERRIDE; 1.223 + 1.224 + NS_IMETHOD SetSelectionFlags(int16_t aInEnable) MOZ_OVERRIDE; 1.225 + NS_IMETHOD GetSelectionFlags(int16_t *aOutEnable) MOZ_OVERRIDE; 1.226 + 1.227 + // nsISelectionController 1.228 + 1.229 + NS_IMETHOD CharacterMove(bool aForward, bool aExtend) MOZ_OVERRIDE; 1.230 + NS_IMETHOD CharacterExtendForDelete() MOZ_OVERRIDE; 1.231 + NS_IMETHOD CharacterExtendForBackspace() MOZ_OVERRIDE; 1.232 + NS_IMETHOD WordMove(bool aForward, bool aExtend) MOZ_OVERRIDE; 1.233 + NS_IMETHOD WordExtendForDelete(bool aForward) MOZ_OVERRIDE; 1.234 + NS_IMETHOD LineMove(bool aForward, bool aExtend) MOZ_OVERRIDE; 1.235 + NS_IMETHOD IntraLineMove(bool aForward, bool aExtend) MOZ_OVERRIDE; 1.236 + NS_IMETHOD PageMove(bool aForward, bool aExtend) MOZ_OVERRIDE; 1.237 + NS_IMETHOD ScrollPage(bool aForward) MOZ_OVERRIDE; 1.238 + NS_IMETHOD ScrollLine(bool aForward) MOZ_OVERRIDE; 1.239 + NS_IMETHOD ScrollCharacter(bool aRight) MOZ_OVERRIDE; 1.240 + NS_IMETHOD CompleteScroll(bool aForward) MOZ_OVERRIDE; 1.241 + NS_IMETHOD CompleteMove(bool aForward, bool aExtend) MOZ_OVERRIDE; 1.242 + NS_IMETHOD SelectAll() MOZ_OVERRIDE; 1.243 + NS_IMETHOD CheckVisibility(nsIDOMNode *node, int16_t startOffset, int16_t EndOffset, bool *_retval) MOZ_OVERRIDE; 1.244 + virtual nsresult CheckVisibilityContent(nsIContent* aNode, int16_t aStartOffset, 1.245 + int16_t aEndOffset, bool* aRetval) MOZ_OVERRIDE; 1.246 + 1.247 + // nsIDocumentObserver 1.248 + NS_DECL_NSIDOCUMENTOBSERVER_BEGINUPDATE 1.249 + NS_DECL_NSIDOCUMENTOBSERVER_ENDUPDATE 1.250 + NS_DECL_NSIDOCUMENTOBSERVER_BEGINLOAD 1.251 + NS_DECL_NSIDOCUMENTOBSERVER_ENDLOAD 1.252 + NS_DECL_NSIDOCUMENTOBSERVER_CONTENTSTATECHANGED 1.253 + NS_DECL_NSIDOCUMENTOBSERVER_DOCUMENTSTATESCHANGED 1.254 + NS_DECL_NSIDOCUMENTOBSERVER_STYLESHEETADDED 1.255 + NS_DECL_NSIDOCUMENTOBSERVER_STYLESHEETREMOVED 1.256 + NS_DECL_NSIDOCUMENTOBSERVER_STYLESHEETAPPLICABLESTATECHANGED 1.257 + NS_DECL_NSIDOCUMENTOBSERVER_STYLERULECHANGED 1.258 + NS_DECL_NSIDOCUMENTOBSERVER_STYLERULEADDED 1.259 + NS_DECL_NSIDOCUMENTOBSERVER_STYLERULEREMOVED 1.260 + 1.261 + // nsIMutationObserver 1.262 + NS_DECL_NSIMUTATIONOBSERVER_CHARACTERDATAWILLCHANGE 1.263 + NS_DECL_NSIMUTATIONOBSERVER_CHARACTERDATACHANGED 1.264 + NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTEWILLCHANGE 1.265 + NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTECHANGED 1.266 + NS_DECL_NSIMUTATIONOBSERVER_CONTENTAPPENDED 1.267 + NS_DECL_NSIMUTATIONOBSERVER_CONTENTINSERTED 1.268 + NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED 1.269 + 1.270 + NS_DECL_NSIOBSERVER 1.271 + 1.272 +#ifdef MOZ_REFLOW_PERF 1.273 + virtual NS_HIDDEN_(void) DumpReflows() MOZ_OVERRIDE; 1.274 + virtual NS_HIDDEN_(void) CountReflows(const char * aName, nsIFrame * aFrame) MOZ_OVERRIDE; 1.275 + virtual NS_HIDDEN_(void) PaintCount(const char * aName, 1.276 + nsRenderingContext* aRenderingContext, 1.277 + nsPresContext* aPresContext, 1.278 + nsIFrame * aFrame, 1.279 + const nsPoint& aOffset, 1.280 + uint32_t aColor) MOZ_OVERRIDE; 1.281 + virtual NS_HIDDEN_(void) SetPaintFrameCount(bool aOn) MOZ_OVERRIDE; 1.282 + virtual bool IsPaintingFrameCounts() MOZ_OVERRIDE; 1.283 +#endif 1.284 + 1.285 +#ifdef DEBUG 1.286 + virtual void ListStyleContexts(nsIFrame *aRootFrame, FILE *out, 1.287 + int32_t aIndent = 0) MOZ_OVERRIDE; 1.288 + 1.289 + virtual void ListStyleSheets(FILE *out, int32_t aIndent = 0) MOZ_OVERRIDE; 1.290 + virtual void VerifyStyleTree() MOZ_OVERRIDE; 1.291 +#endif 1.292 + 1.293 +#ifdef PR_LOGGING 1.294 + static PRLogModuleInfo* gLog; 1.295 +#endif 1.296 + 1.297 + virtual NS_HIDDEN_(void) DisableNonTestMouseEvents(bool aDisable) MOZ_OVERRIDE; 1.298 + 1.299 + virtual void UpdateCanvasBackground() MOZ_OVERRIDE; 1.300 + 1.301 + virtual void AddCanvasBackgroundColorItem(nsDisplayListBuilder& aBuilder, 1.302 + nsDisplayList& aList, 1.303 + nsIFrame* aFrame, 1.304 + const nsRect& aBounds, 1.305 + nscolor aBackstopColor, 1.306 + uint32_t aFlags) MOZ_OVERRIDE; 1.307 + 1.308 + virtual void AddPrintPreviewBackgroundItem(nsDisplayListBuilder& aBuilder, 1.309 + nsDisplayList& aList, 1.310 + nsIFrame* aFrame, 1.311 + const nsRect& aBounds) MOZ_OVERRIDE; 1.312 + 1.313 + virtual nscolor ComputeBackstopColor(nsView* aDisplayRoot) MOZ_OVERRIDE; 1.314 + 1.315 + virtual NS_HIDDEN_(nsresult) SetIsActive(bool aIsActive) MOZ_OVERRIDE; 1.316 + 1.317 + virtual bool GetIsViewportOverridden() MOZ_OVERRIDE { return mViewportOverridden; } 1.318 + 1.319 + virtual bool IsLayoutFlushObserver() MOZ_OVERRIDE 1.320 + { 1.321 + return GetPresContext()->RefreshDriver()-> 1.322 + IsLayoutFlushObserver(this); 1.323 + } 1.324 + 1.325 + virtual void LoadComplete() MOZ_OVERRIDE; 1.326 + 1.327 + void AddSizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf, 1.328 + nsArenaMemoryStats *aArenaObjectsSize, 1.329 + size_t *aPresShellSize, 1.330 + size_t *aStyleSetsSize, 1.331 + size_t *aTextRunsSize, 1.332 + size_t *aPresContextSize) MOZ_OVERRIDE; 1.333 + size_t SizeOfTextRuns(mozilla::MallocSizeOf aMallocSizeOf) const; 1.334 + 1.335 + virtual void AddInvalidateHiddenPresShellObserver(nsRefreshDriver *aDriver) MOZ_OVERRIDE; 1.336 + 1.337 + // This data is stored as a content property (nsGkAtoms::scrolling) on 1.338 + // mContentToScrollTo when we have a pending ScrollIntoView. 1.339 + struct ScrollIntoViewData { 1.340 + ScrollAxis mContentScrollVAxis; 1.341 + ScrollAxis mContentScrollHAxis; 1.342 + uint32_t mContentToScrollToFlags; 1.343 + }; 1.344 + 1.345 + virtual void ScheduleImageVisibilityUpdate() MOZ_OVERRIDE; 1.346 + 1.347 + virtual void RebuildImageVisibility(const nsDisplayList& aList) MOZ_OVERRIDE; 1.348 + 1.349 + virtual void EnsureImageInVisibleList(nsIImageLoadingContent* aImage) MOZ_OVERRIDE; 1.350 + 1.351 + virtual void RemoveImageFromVisibleList(nsIImageLoadingContent* aImage) MOZ_OVERRIDE; 1.352 + 1.353 + virtual bool AssumeAllImagesVisible() MOZ_OVERRIDE; 1.354 + 1.355 + virtual void RestyleShadowRoot(mozilla::dom::ShadowRoot* aShadowRoot); 1.356 + 1.357 + void SetNextPaintCompressed() { mNextPaintCompressed = true; } 1.358 + 1.359 +protected: 1.360 + virtual ~PresShell(); 1.361 + 1.362 + void HandlePostedReflowCallbacks(bool aInterruptible); 1.363 + void CancelPostedReflowCallbacks(); 1.364 + 1.365 + void UnsuppressAndInvalidate(); 1.366 + 1.367 + void WillCauseReflow() { 1.368 + nsContentUtils::AddScriptBlocker(); 1.369 + ++mChangeNestCount; 1.370 + } 1.371 + nsresult DidCauseReflow(); 1.372 + friend class nsAutoCauseReflowNotifier; 1.373 + 1.374 + void DispatchTouchEvent(mozilla::WidgetEvent* aEvent, 1.375 + nsEventStatus* aStatus, 1.376 + nsPresShellEventCB* aEventCB, 1.377 + bool aTouchIsNew); 1.378 + 1.379 + void WillDoReflow(); 1.380 + 1.381 + /** 1.382 + * Callback handler for whether reflow happened. 1.383 + * 1.384 + * @param aInterruptible Whether or not reflow interruption is allowed. 1.385 + * @param aWasInterrupted Whether or not the reflow was interrupted earlier. 1.386 + * 1.387 + */ 1.388 + void DidDoReflow(bool aInterruptible, bool aWasInterrupted); 1.389 + // ProcessReflowCommands returns whether we processed all our dirty roots 1.390 + // without interruptions. 1.391 + bool ProcessReflowCommands(bool aInterruptible); 1.392 + // MaybeScheduleReflow checks if posting a reflow is needed, then checks if 1.393 + // the last reflow was interrupted. In the interrupted case ScheduleReflow is 1.394 + // called off a timer, otherwise it is called directly. 1.395 + void MaybeScheduleReflow(); 1.396 + // Actually schedules a reflow. This should only be called by 1.397 + // MaybeScheduleReflow and the reflow timer ScheduleReflowOffTimer 1.398 + // sets up. 1.399 + void ScheduleReflow(); 1.400 + 1.401 + // Reflow regardless of whether the override bit has been set. 1.402 + nsresult ResizeReflowIgnoreOverride(nscoord aWidth, nscoord aHeight); 1.403 + 1.404 + // DoReflow returns whether the reflow finished without interruption 1.405 + bool DoReflow(nsIFrame* aFrame, bool aInterruptible); 1.406 +#ifdef DEBUG 1.407 + void DoVerifyReflow(); 1.408 + void VerifyHasDirtyRootAncestor(nsIFrame* aFrame); 1.409 +#endif 1.410 + 1.411 + // Helper for ScrollContentIntoView 1.412 + void DoScrollContentIntoView(); 1.413 + 1.414 + /** 1.415 + * Initialize cached font inflation preference values and do an initial 1.416 + * computation to determine if font inflation is enabled. 1.417 + * 1.418 + * @see nsLayoutUtils::sFontSizeInflationEmPerLine 1.419 + * @see nsLayoutUtils::sFontSizeInflationMinTwips 1.420 + * @see nsLayoutUtils::sFontSizeInflationLineThreshold 1.421 + */ 1.422 + void SetupFontInflation(); 1.423 + 1.424 + friend struct AutoRenderingStateSaveRestore; 1.425 + friend struct RenderingState; 1.426 + 1.427 + struct RenderingState { 1.428 + RenderingState(PresShell* aPresShell) 1.429 + : mXResolution(aPresShell->mXResolution) 1.430 + , mYResolution(aPresShell->mYResolution) 1.431 + , mRenderFlags(aPresShell->mRenderFlags) 1.432 + { } 1.433 + float mXResolution; 1.434 + float mYResolution; 1.435 + RenderFlags mRenderFlags; 1.436 + }; 1.437 + 1.438 + struct AutoSaveRestoreRenderingState { 1.439 + AutoSaveRestoreRenderingState(PresShell* aPresShell) 1.440 + : mPresShell(aPresShell) 1.441 + , mOldState(aPresShell) 1.442 + {} 1.443 + 1.444 + ~AutoSaveRestoreRenderingState() 1.445 + { 1.446 + mPresShell->mRenderFlags = mOldState.mRenderFlags; 1.447 + mPresShell->mXResolution = mOldState.mXResolution; 1.448 + mPresShell->mYResolution = mOldState.mYResolution; 1.449 + } 1.450 + 1.451 + PresShell* mPresShell; 1.452 + RenderingState mOldState; 1.453 + }; 1.454 + static RenderFlags ChangeFlag(RenderFlags aFlags, bool aOnOff, 1.455 + eRenderFlag aFlag) 1.456 + { 1.457 + return aOnOff ? (aFlags | aFlag) : (aFlag & ~aFlag); 1.458 + } 1.459 + 1.460 + 1.461 + void SetRenderingState(const RenderingState& aState); 1.462 + 1.463 + friend class nsPresShellEventCB; 1.464 + 1.465 + bool mCaretEnabled; 1.466 +#ifdef DEBUG 1.467 + nsStyleSet* CloneStyleSet(nsStyleSet* aSet); 1.468 + bool VerifyIncrementalReflow(); 1.469 + bool mInVerifyReflow; 1.470 + void ShowEventTargetDebug(); 1.471 +#endif 1.472 + 1.473 + void RecordStyleSheetChange(nsIStyleSheet* aStyleSheet); 1.474 + 1.475 + /** 1.476 + * methods that manage rules that are used to implement the associated preferences 1.477 + * - initially created for bugs 31816, 20760, 22963 1.478 + */ 1.479 + nsresult ClearPreferenceStyleRules(void); 1.480 + nsresult CreatePreferenceStyleSheet(void); 1.481 + nsresult SetPrefLinkRules(void); 1.482 + nsresult SetPrefFocusRules(void); 1.483 + nsresult SetPrefNoScriptRule(); 1.484 + nsresult SetPrefNoFramesRule(void); 1.485 + 1.486 + // methods for painting a range to an offscreen buffer 1.487 + 1.488 + // given a display list, clip the items within the list to 1.489 + // the range 1.490 + nsRect ClipListToRange(nsDisplayListBuilder *aBuilder, 1.491 + nsDisplayList* aList, 1.492 + nsRange* aRange); 1.493 + 1.494 + // create a RangePaintInfo for the range aRange containing the 1.495 + // display list needed to paint the range to a surface 1.496 + RangePaintInfo* CreateRangePaintInfo(nsIDOMRange* aRange, 1.497 + nsRect& aSurfaceRect, 1.498 + bool aForPrimarySelection); 1.499 + 1.500 + /* 1.501 + * Paint the items to a new surface and return it. 1.502 + * 1.503 + * aSelection - selection being painted, if any 1.504 + * aRegion - clip region, if any 1.505 + * aArea - area that the surface occupies, relative to the root frame 1.506 + * aPoint - reference point, typically the mouse position 1.507 + * aScreenRect - [out] set to the area of the screen the painted area should 1.508 + * be displayed at 1.509 + */ 1.510 + mozilla::TemporaryRef<SourceSurface> 1.511 + PaintRangePaintInfo(nsTArray<nsAutoPtr<RangePaintInfo> >* aItems, 1.512 + nsISelection* aSelection, 1.513 + nsIntRegion* aRegion, 1.514 + nsRect aArea, 1.515 + nsIntPoint& aPoint, 1.516 + nsIntRect* aScreenRect); 1.517 + 1.518 + /** 1.519 + * Methods to handle changes to user and UA sheet lists that we get 1.520 + * notified about. 1.521 + */ 1.522 + void AddUserSheet(nsISupports* aSheet); 1.523 + void AddAgentSheet(nsISupports* aSheet); 1.524 + void AddAuthorSheet(nsISupports* aSheet); 1.525 + void RemoveSheet(nsStyleSet::sheetType aType, nsISupports* aSheet); 1.526 + 1.527 + // Hide a view if it is a popup 1.528 + void HideViewIfPopup(nsView* aView); 1.529 + 1.530 + // Utility method to restore the root scrollframe state 1.531 + void RestoreRootScrollPosition(); 1.532 + 1.533 + void MaybeReleaseCapturingContent() 1.534 + { 1.535 + nsRefPtr<nsFrameSelection> frameSelection = FrameSelection(); 1.536 + if (frameSelection) { 1.537 + frameSelection->SetMouseDownState(false); 1.538 + } 1.539 + if (gCaptureInfo.mContent && 1.540 + gCaptureInfo.mContent->OwnerDoc() == mDocument) { 1.541 + SetCapturingContent(nullptr, 0); 1.542 + } 1.543 + } 1.544 + 1.545 + nsresult HandleRetargetedEvent(mozilla::WidgetEvent* aEvent, 1.546 + nsEventStatus* aStatus, 1.547 + nsIContent* aTarget) 1.548 + { 1.549 + PushCurrentEventInfo(nullptr, nullptr); 1.550 + mCurrentEventContent = aTarget; 1.551 + nsresult rv = NS_OK; 1.552 + if (GetCurrentEventFrame()) { 1.553 + rv = HandleEventInternal(aEvent, aStatus); 1.554 + } 1.555 + PopCurrentEventInfo(); 1.556 + return rv; 1.557 + } 1.558 + 1.559 + class DelayedEvent 1.560 + { 1.561 + public: 1.562 + virtual ~DelayedEvent() { } 1.563 + virtual void Dispatch() { } 1.564 + }; 1.565 + 1.566 + class DelayedInputEvent : public DelayedEvent 1.567 + { 1.568 + public: 1.569 + virtual void Dispatch() MOZ_OVERRIDE; 1.570 + 1.571 + protected: 1.572 + DelayedInputEvent(); 1.573 + virtual ~DelayedInputEvent(); 1.574 + 1.575 + mozilla::WidgetInputEvent* mEvent; 1.576 + }; 1.577 + 1.578 + class DelayedMouseEvent : public DelayedInputEvent 1.579 + { 1.580 + public: 1.581 + DelayedMouseEvent(mozilla::WidgetMouseEvent* aEvent); 1.582 + }; 1.583 + 1.584 + class DelayedKeyEvent : public DelayedInputEvent 1.585 + { 1.586 + public: 1.587 + DelayedKeyEvent(mozilla::WidgetKeyboardEvent* aEvent); 1.588 + }; 1.589 + 1.590 + // Check if aEvent is a mouse event and record the mouse location for later 1.591 + // synth mouse moves. 1.592 + void RecordMouseLocation(mozilla::WidgetGUIEvent* aEvent); 1.593 + class nsSynthMouseMoveEvent MOZ_FINAL : public nsARefreshObserver { 1.594 + public: 1.595 + nsSynthMouseMoveEvent(PresShell* aPresShell, bool aFromScroll) 1.596 + : mPresShell(aPresShell), mFromScroll(aFromScroll) { 1.597 + NS_ASSERTION(mPresShell, "null parameter"); 1.598 + } 1.599 + 1.600 + private: 1.601 + // Private destructor, to discourage deletion outside of Release(): 1.602 + ~nsSynthMouseMoveEvent() { 1.603 + Revoke(); 1.604 + } 1.605 + 1.606 + public: 1.607 + NS_INLINE_DECL_REFCOUNTING(nsSynthMouseMoveEvent) 1.608 + 1.609 + void Revoke() { 1.610 + if (mPresShell) { 1.611 + mPresShell->GetPresContext()->RefreshDriver()-> 1.612 + RemoveRefreshObserver(this, Flush_Display); 1.613 + mPresShell = nullptr; 1.614 + } 1.615 + } 1.616 + virtual void WillRefresh(mozilla::TimeStamp aTime) MOZ_OVERRIDE { 1.617 + if (mPresShell) { 1.618 + nsRefPtr<PresShell> shell = mPresShell; 1.619 + shell->ProcessSynthMouseMoveEvent(mFromScroll); 1.620 + } 1.621 + } 1.622 + private: 1.623 + PresShell* mPresShell; 1.624 + bool mFromScroll; 1.625 + }; 1.626 + void ProcessSynthMouseMoveEvent(bool aFromScroll); 1.627 + 1.628 + void QueryIsActive(); 1.629 + nsresult UpdateImageLockingState(); 1.630 + 1.631 +#ifdef ANDROID 1.632 + nsIDocument* GetTouchEventTargetDocument(); 1.633 +#endif 1.634 + bool InZombieDocument(nsIContent *aContent); 1.635 + already_AddRefed<nsIPresShell> GetParentPresShellForEventHandling(); 1.636 + nsIContent* GetCurrentEventContent(); 1.637 + nsIFrame* GetCurrentEventFrame(); 1.638 + nsresult RetargetEventToParent(mozilla::WidgetGUIEvent* aEvent, 1.639 + nsEventStatus* aEventStatus); 1.640 + void PushCurrentEventInfo(nsIFrame* aFrame, nsIContent* aContent); 1.641 + void PopCurrentEventInfo(); 1.642 + nsresult HandleEventInternal(mozilla::WidgetEvent* aEvent, 1.643 + nsEventStatus* aStatus); 1.644 + nsresult HandlePositionedEvent(nsIFrame* aTargetFrame, 1.645 + mozilla::WidgetGUIEvent* aEvent, 1.646 + nsEventStatus* aEventStatus); 1.647 + // This returns the focused DOM window under our top level window. 1.648 + // I.e., when we are deactive, this returns the *last* focused DOM window. 1.649 + already_AddRefed<nsPIDOMWindow> GetFocusedDOMWindowInOurWindow(); 1.650 + 1.651 + /* 1.652 + * This and the next two helper methods are used to target and position the 1.653 + * context menu when the keyboard shortcut is used to open it. 1.654 + * 1.655 + * If another menu is open, the context menu is opened relative to the 1.656 + * active menuitem within the menu, or the menu itself if no item is active. 1.657 + * Otherwise, if the caret is visible, the menu is opened near the caret. 1.658 + * Otherwise, if a selectable list such as a listbox is focused, the 1.659 + * current item within the menu is opened relative to this item. 1.660 + * Otherwise, the context menu is opened at the topleft corner of the 1.661 + * view. 1.662 + * 1.663 + * Returns true if the context menu event should fire and false if it should 1.664 + * not. 1.665 + */ 1.666 + bool AdjustContextMenuKeyEvent(mozilla::WidgetMouseEvent* aEvent); 1.667 + 1.668 + // 1.669 + bool PrepareToUseCaretPosition(nsIWidget* aEventWidget, nsIntPoint& aTargetPt); 1.670 + 1.671 + // Get the selected item and coordinates in device pixels relative to root 1.672 + // document's root view for element, first ensuring the element is onscreen 1.673 + void GetCurrentItemAndPositionForElement(nsIDOMElement *aCurrentEl, 1.674 + nsIContent **aTargetToUse, 1.675 + mozilla::LayoutDeviceIntPoint& aTargetPt, 1.676 + nsIWidget *aRootWidget); 1.677 + 1.678 + void FireResizeEvent(); 1.679 + static void AsyncResizeEventCallback(nsITimer* aTimer, void* aPresShell); 1.680 + 1.681 + virtual void SynthesizeMouseMove(bool aFromScroll) MOZ_OVERRIDE; 1.682 + 1.683 + PresShell* GetRootPresShell(); 1.684 + 1.685 + nscolor GetDefaultBackgroundColorToDraw(); 1.686 + 1.687 + DOMHighResTimeStamp GetPerformanceNow(); 1.688 + 1.689 + // The callback for the mPaintSuppressionTimer timer. 1.690 + static void sPaintSuppressionCallback(nsITimer* aTimer, void* aPresShell); 1.691 + 1.692 + // The callback for the mReflowContinueTimer timer. 1.693 + static void sReflowContinueCallback(nsITimer* aTimer, void* aPresShell); 1.694 + bool ScheduleReflowOffTimer(); 1.695 + 1.696 + // Widget notificiations 1.697 + virtual void WindowSizeMoveDone() MOZ_OVERRIDE; 1.698 + virtual void SysColorChanged() MOZ_OVERRIDE { mPresContext->SysColorChanged(); } 1.699 + virtual void ThemeChanged() MOZ_OVERRIDE { mPresContext->ThemeChanged(); } 1.700 + virtual void BackingScaleFactorChanged() MOZ_OVERRIDE { mPresContext->UIResolutionChanged(); } 1.701 + 1.702 + virtual void PausePainting() MOZ_OVERRIDE; 1.703 + virtual void ResumePainting() MOZ_OVERRIDE; 1.704 + 1.705 + void UpdateImageVisibility(); 1.706 + void UpdateActivePointerState(mozilla::WidgetGUIEvent* aEvent); 1.707 + 1.708 + nsRevocableEventPtr<nsRunnableMethod<PresShell> > mUpdateImageVisibilityEvent; 1.709 + 1.710 + void ClearVisibleImagesList(); 1.711 + static void ClearImageVisibilityVisited(nsView* aView, bool aClear); 1.712 + static void MarkImagesInListVisible(const nsDisplayList& aList); 1.713 + 1.714 + void EvictTouches(); 1.715 + 1.716 + // A list of images that are visible or almost visible. 1.717 + nsTHashtable< nsRefPtrHashKey<nsIImageLoadingContent> > mVisibleImages; 1.718 + 1.719 +#ifdef DEBUG 1.720 + // The reflow root under which we're currently reflowing. Null when 1.721 + // not in reflow. 1.722 + nsIFrame* mCurrentReflowRoot; 1.723 + uint32_t mUpdateCount; 1.724 +#endif 1.725 + 1.726 +#ifdef MOZ_REFLOW_PERF 1.727 + ReflowCountMgr* mReflowCountMgr; 1.728 +#endif 1.729 + 1.730 + // This is used for synthetic mouse events that are sent when what is under 1.731 + // the mouse pointer may have changed without the mouse moving (eg scrolling, 1.732 + // change to the document contents). 1.733 + // It is set only on a presshell for a root document, this value represents 1.734 + // the last observed location of the mouse relative to that root document. It 1.735 + // is set to (NS_UNCONSTRAINEDSIZE, NS_UNCONSTRAINEDSIZE) if the mouse isn't 1.736 + // over our window or there is no last observed mouse location for some 1.737 + // reason. 1.738 + nsPoint mMouseLocation; 1.739 + 1.740 + // mStyleSet owns it but we maintain a ref, may be null 1.741 + nsRefPtr<nsCSSStyleSheet> mPrefStyleSheet; 1.742 + 1.743 + // Set of frames that we should mark with NS_FRAME_HAS_DIRTY_CHILDREN after 1.744 + // we finish reflowing mCurrentReflowRoot. 1.745 + nsTHashtable<nsPtrHashKey<nsIFrame> > mFramesToDirty; 1.746 + 1.747 + // Reflow roots that need to be reflowed. 1.748 + nsTArray<nsIFrame*> mDirtyRoots; 1.749 + 1.750 + nsTArray<nsAutoPtr<DelayedEvent> > mDelayedEvents; 1.751 + nsRevocableEventPtr<nsRunnableMethod<PresShell> > mResizeEvent; 1.752 + nsCOMPtr<nsITimer> mAsyncResizeEventTimer; 1.753 +private: 1.754 + nsIFrame* mCurrentEventFrame; 1.755 + nsCOMPtr<nsIContent> mCurrentEventContent; 1.756 + nsTArray<nsIFrame*> mCurrentEventFrameStack; 1.757 + nsCOMArray<nsIContent> mCurrentEventContentStack; 1.758 +protected: 1.759 + nsRevocableEventPtr<nsSynthMouseMoveEvent> mSynthMouseMoveEvent; 1.760 + nsCOMPtr<nsIContent> mLastAnchorScrolledTo; 1.761 + nsRefPtr<nsCaret> mCaret; 1.762 + nsRefPtr<nsCaret> mOriginalCaret; 1.763 + nsCallbackEventRequest* mFirstCallbackEventRequest; 1.764 + nsCallbackEventRequest* mLastCallbackEventRequest; 1.765 + 1.766 + // This timer controls painting suppression. Until it fires 1.767 + // or all frames are constructed, we won't paint anything but 1.768 + // our <body> background and scrollbars. 1.769 + nsCOMPtr<nsITimer> mPaintSuppressionTimer; 1.770 + 1.771 + // At least on Win32 and Mac after interupting a reflow we need to post 1.772 + // the resume reflow event off a timer to avoid event starvation because 1.773 + // posted messages are processed before other messages when the modal 1.774 + // moving/sizing loop is running, see bug 491700 for details. 1.775 + nsCOMPtr<nsITimer> mReflowContinueTimer; 1.776 + 1.777 + nsCOMPtr<nsITimer> mDelayedPaintTimer; 1.778 + 1.779 + // The `performance.now()` value when we last started to process reflows. 1.780 + DOMHighResTimeStamp mLastReflowStart; 1.781 + 1.782 + mozilla::TimeStamp mLoadBegin; // used to time loads 1.783 + 1.784 + // Information needed to properly handle scrolling content into view if the 1.785 + // pre-scroll reflow flush can be interrupted. mContentToScrollTo is 1.786 + // non-null between the initial scroll attempt and the first time we finish 1.787 + // processing all our dirty roots. mContentToScrollTo has a content property 1.788 + // storing the details for the scroll operation, see ScrollIntoViewData above. 1.789 + nsCOMPtr<nsIContent> mContentToScrollTo; 1.790 + 1.791 + nscoord mLastAnchorScrollPositionY; 1.792 + 1.793 + // This is used to protect ourselves from triggering reflow while in the 1.794 + // middle of frame construction and the like... it really shouldn't be 1.795 + // needed, one hopes, but it is for now. 1.796 + uint16_t mChangeNestCount; 1.797 + 1.798 + bool mDocumentLoading : 1; 1.799 + bool mIgnoreFrameDestruction : 1; 1.800 + bool mHaveShutDown : 1; 1.801 + bool mViewportOverridden : 1; 1.802 + bool mLastRootReflowHadUnconstrainedHeight : 1; 1.803 + bool mNoDelayedMouseEvents : 1; 1.804 + bool mNoDelayedKeyEvents : 1; 1.805 + 1.806 + // We've been disconnected from the document. We will refuse to paint the 1.807 + // document until either our timer fires or all frames are constructed. 1.808 + bool mIsDocumentGone : 1; 1.809 + 1.810 + // Indicates that it is safe to unlock painting once all pending reflows 1.811 + // have been processed. 1.812 + bool mShouldUnsuppressPainting : 1; 1.813 + 1.814 + bool mAsyncResizeTimerIsActive : 1; 1.815 + bool mInResize : 1; 1.816 + 1.817 + bool mImageVisibilityVisited : 1; 1.818 + 1.819 + bool mNextPaintCompressed : 1; 1.820 + 1.821 + static bool sDisableNonTestMouseEvents; 1.822 +}; 1.823 + 1.824 +#endif /* !defined(nsPresShell_h_) */