Bug 1166147 - Part3: Override GetWritingMode() and make it more robustly defer to root element, to avoid truncating printed vertical-WM docs. draft
authorNeerja Pancholi <npancholi@mozilla.com>
Mon, 30 Jan 2017 13:22:45 -0800
changeset 468256 9fd0800f2e39e5eb513fcbe875bdcb6d543a6577
parent 468253 ab4d166996b632f148101de309bf5be1ae079a20
child 468257 256de1b3dc77afbed96f72ade497d6db41f8e674
child 468315 05c25e5cd2f980ac43aa89c4e04ac13caf094ffe
child 468316 734709d24c7de902e427f4c7edfcab1e69fe7eda
child 468317 dbb18c20b8126d03d5290127ea4b945ddb9f7f2a
child 468318 16a90f05f82851df8232e2272d1d5224a65ebbac
child 468319 dcc2433e3ef5cb20756038bc826b791e71160cde
child 468320 e4961a4bb44bae7ebed2f5b5dd5aaceb220debf1
child 468321 c2a5be2ff2cdd75a812fea89b4df6779f65657df
child 468322 9a3fa699ac551f6f68776f060d218467f11fa695
child 468323 e616751b9537687aaf8a2305de52fcb1c23e4c34
child 468324 88cd994c04f41d106acadd54e036248c261e3c00
child 468375 eca801a9883edba28da42b08768843c9590d69f8
push id43401
push userbmo:npancholi@mozilla.com
push dateMon, 30 Jan 2017 23:36:23 +0000
bugs1166147
milestone54.0a1
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
layout/generic/nsCanvasFrame.h
layout/generic/nsFrame.cpp
layout/generic/nsFrame.h
layout/generic/nsPageContentFrame.cpp
layout/generic/nsPageContentFrame.h
layout/generic/nsPageFrame.h
layout/generic/nsSimplePageSequenceFrame.h
--- 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,