Bug 1166147 - Part3: Override GetWritingMode() and make it more robustly defer to root element, to avoid truncating printed vertical-WM docs.
MozReview-Commit-ID: IYM3gzf1CpS
--- a/layout/generic/nsCanvasFrame.h
+++ b/layout/generic/nsCanvasFrame.h
@@ -39,26 +39,19 @@ public:
NS_DECL_QUERYFRAME_TARGET(nsCanvasFrame)
NS_DECL_QUERYFRAME
NS_DECL_FRAMEARENA_HELPERS
virtual void DestroyFrom(nsIFrame* aDestructRoot) override;
- virtual mozilla::WritingMode GetWritingMode() const override
+ mozilla::WritingMode GetWritingMode() const override
{
- nsIContent* rootElem = GetContent();
- if (rootElem) {
- nsIFrame* rootElemFrame = rootElem->GetPrimaryFrame();
- if (rootElemFrame) {
- return rootElemFrame->GetWritingMode();
- }
- }
- return nsIFrame::GetWritingMode();
+ return nsFrame::GetWritingModeDeferringToRootElem();
}
#ifdef DEBUG
virtual void SetInitialChildList(ChildListID aListID,
nsFrameList& aChildList) override;
virtual void AppendFrames(ChildListID aListID,
nsFrameList& aFrameList) override;
virtual void InsertFrames(ChildListID aListID,
--- a/layout/generic/nsFrame.cpp
+++ b/layout/generic/nsFrame.cpp
@@ -3015,16 +3015,29 @@ nsFrame::FireDOMEvent(const nsAString& a
if (target) {
RefPtr<AsyncEventDispatcher> asyncDispatcher =
new AsyncEventDispatcher(target, aDOMEventName, true, false);
DebugOnly<nsresult> rv = asyncDispatcher->PostDOMEvent();
NS_ASSERTION(NS_SUCCEEDED(rv), "AsyncEventDispatcher failed to dispatch");
}
}
+WritingMode
+nsFrame::GetWritingModeDeferringToRootElem() const
+{
+ Element* rootElem = PresContext()->Document()->GetRootElement();
+ if (rootElem) {
+ nsIFrame* primaryFrame = rootElem->GetPrimaryFrame();
+ if (primaryFrame) {
+ return primaryFrame->GetWritingMode();
+ }
+ }
+ return nsIFrame::GetWritingMode();
+}
+
nsresult
nsFrame::HandleEvent(nsPresContext* aPresContext,
WidgetGUIEvent* aEvent,
nsEventStatus* aEventStatus)
{
if (aEvent->mMessage == eMouseMove) {
// XXX If the second argument of HandleDrag() is WidgetMouseEvent,
--- a/layout/generic/nsFrame.h
+++ b/layout/generic/nsFrame.h
@@ -683,16 +683,18 @@ protected:
void GetBoxName(nsAutoString& aName) override;
#endif
nsBoxLayoutMetrics* BoxMetrics() const;
// Fire DOM event. If no aContent argument use frame's mContent.
void FireDOMEvent(const nsAString& aDOMEventName, nsIContent *aContent = nullptr);
+ mozilla::WritingMode GetWritingModeDeferringToRootElem() const;
+
private:
void BoxReflow(nsBoxLayoutState& aState,
nsPresContext* aPresContext,
ReflowOutput& aDesiredSize,
nsRenderingContext* aRenderingContext,
nscoord aX,
nscoord aY,
nscoord aWidth,
--- a/layout/generic/nsPageContentFrame.cpp
+++ b/layout/generic/nsPageContentFrame.cpp
@@ -106,17 +106,17 @@ nsPageContentFrame::Reflow(nsPresContext
FinishAndStoreOverflow(&aDesiredSize);
NS_FRAME_SET_TRUNCATION(aStatus, aReflowInput, aDesiredSize);
}
nsIAtom*
nsPageContentFrame::GetType() const
{
- return nsGkAtoms::pageContentFrame;
+ return nsGkAtoms::pageContentFrame;
}
#ifdef DEBUG_FRAME_DUMP
nsresult
nsPageContentFrame::GetFrameName(nsAString& aResult) const
{
return MakeFrameName(NS_LITERAL_STRING("PageContent"), aResult);
}
--- a/layout/generic/nsPageContentFrame.h
+++ b/layout/generic/nsPageContentFrame.h
@@ -38,17 +38,22 @@ public:
virtual bool HasTransformGetter() const override { return true; }
/**
* Get the "type" of the frame
*
* @see nsGkAtoms::pageContentFrame
*/
virtual nsIAtom* GetType() const override;
-
+
+ mozilla::WritingMode GetWritingMode() const override
+ {
+ return nsFrame::GetWritingModeDeferringToRootElem();
+ }
+
#ifdef DEBUG_FRAME_DUMP
// Debugging
virtual nsresult GetFrameName(nsAString& aResult) const override;
#endif
protected:
explicit nsPageContentFrame(nsStyleContext* aContext) : ViewportFrame(aContext) {}
--- a/layout/generic/nsPageFrame.h
+++ b/layout/generic/nsPageFrame.h
@@ -27,23 +27,28 @@ public:
ReflowOutput& aDesiredSize,
const ReflowInput& aMaxSize,
nsReflowStatus& aStatus) override;
virtual void BuildDisplayList(nsDisplayListBuilder* aBuilder,
const nsRect& aDirtyRect,
const nsDisplayListSet& aLists) override;
+ mozilla::WritingMode GetWritingMode() const override
+ {
+ return nsFrame::GetWritingModeDeferringToRootElem();
+ }
+
/**
* Get the "type" of the frame
*
* @see nsGkAtoms::pageFrame
*/
virtual nsIAtom* GetType() const override;
-
+
#ifdef DEBUG_FRAME_DUMP
virtual nsresult GetFrameName(nsAString& aResult) const override;
#endif
//////////////////
// For Printing
//////////////////
--- a/layout/generic/nsSimplePageSequenceFrame.h
+++ b/layout/generic/nsSimplePageSequenceFrame.h
@@ -55,16 +55,21 @@ class nsSimplePageSequenceFrame : public
public nsIPageSequenceFrame {
public:
friend nsSimplePageSequenceFrame* NS_NewSimplePageSequenceFrame(nsIPresShell* aPresShell,
nsStyleContext* aContext);
NS_DECL_QUERYFRAME
NS_DECL_FRAMEARENA_HELPERS
+ mozilla::WritingMode GetWritingMode() const override
+ {
+ return nsFrame::GetWritingModeDeferringToRootElem();
+ }
+
// nsIFrame
void Reflow(nsPresContext* aPresContext,
ReflowOutput& aDesiredSize,
const ReflowInput& aMaxSize,
nsReflowStatus& aStatus) override;
void BuildDisplayList(nsDisplayListBuilder* aBuilder,
const nsRect& aDirtyRect,