bug 1311604 consider block flow direction in vertical writing mode native widget layout r?jfkthame draft
authorKarl Tomlinson <karlt+@karlt.net>
Thu, 20 Oct 2016 17:57:55 +1300
changeset 427341 1a77a7688262cb33559d8a989b89714f0f945fe7
parent 427289 998ad5a74da80fe63664a8dcf30d8f269ffe4e65
child 427342 c3564baf9fe56bb4d6e13df5b7a812857aa21757
push id32989
push userktomlinson@mozilla.com
push dateThu, 20 Oct 2016 07:49:37 +0000
reviewersjfkthame
bugs1311604
milestone52.0a1
bug 1311604 consider block flow direction in vertical writing mode native widget layout r?jfkthame This follows the same approach of considering block flow for all widgets (in addition to resizers) as done for other toolkits in https://hg.mozilla.org/mozilla-central/rev/4a65cacf8a37#l3.10 MozReview-Commit-ID: Ca3SMs1k2Tj
widget/gtk/nsNativeThemeGTK.cpp
widget/gtk/nsNativeThemeGTK.h
widget/nsNativeTheme.cpp
widget/nsNativeTheme.h
--- a/widget/gtk/nsNativeThemeGTK.cpp
+++ b/widget/gtk/nsNativeThemeGTK.cpp
@@ -144,29 +144,25 @@ static bool IsWidgetStateSafe(uint8_t* a
 static void SetWidgetStateSafe(uint8_t *aSafeVector,
                                uint8_t aWidgetType,
                                GtkWidgetState *aWidgetState)
 {
   uint8_t key = GetWidgetStateKey(aWidgetType, aWidgetState);
   aSafeVector[key >> 3] |= (1 << (key & 7));
 }
 
-static GtkTextDirection GetTextDirection(nsIFrame* aFrame)
+/* static */ GtkTextDirection
+nsNativeThemeGTK::GetTextDirection(nsIFrame* aFrame)
 {
-  if (!aFrame)
-    return GTK_TEXT_DIR_NONE;
-
-  switch (aFrame->StyleVisibility()->mDirection) {
-    case NS_STYLE_DIRECTION_RTL:
-      return GTK_TEXT_DIR_RTL;
-    case NS_STYLE_DIRECTION_LTR:
-      return GTK_TEXT_DIR_LTR;
-  }
-
-  return GTK_TEXT_DIR_NONE;
+  // IsFrameRTL() treats vertical-rl modes as right-to-left (in addition to
+  // horizontal text with direction=RTL), rather than just considering the
+  // text direction.  GtkTextDirection does not have distinct values for
+  // vertical writing modes, but considering the block flow direction is
+  // important for resizers and scrollbar elements, at least.
+  return IsFrameRTL(aFrame) ? GTK_TEXT_DIR_RTL : GTK_TEXT_DIR_LTR;
 }
 
 // Returns positive for negative margins (otherwise 0).
 gint
 nsNativeThemeGTK::GetTabMarginPixels(nsIFrame* aFrame)
 {
   nscoord margin =
     IsBottomTab(aFrame) ? aFrame->GetUsedMargin().top
@@ -1114,24 +1110,17 @@ NS_IMETHODIMP
 nsNativeThemeGTK::DrawWidgetBackground(nsRenderingContext* aContext,
                                        nsIFrame* aFrame,
                                        uint8_t aWidgetType,
                                        const nsRect& aRect,
                                        const nsRect& aDirtyRect)
 {
   GtkWidgetState state;
   WidgetNodeType gtkWidgetType;
-  // For resizer drawing, we want IsFrameRTL, which treats vertical-rl modes
-  // as right-to-left (in addition to horizontal text with direction=RTL),
-  // rather than just considering the text direction.
-  // This will make resizers on vertically-oriented elements render properly.
-  GtkTextDirection direction =
-    aWidgetType == NS_THEME_RESIZER
-    ? (IsFrameRTL(aFrame) ? GTK_TEXT_DIR_RTL : GTK_TEXT_DIR_LTR)
-    : GetTextDirection(aFrame);
+  GtkTextDirection direction = GetTextDirection(aFrame);
   gint flags;
   if (!GetGtkWidgetAndState(aWidgetType, aFrame, gtkWidgetType, &state,
                             &flags))
     return NS_OK;
 
   gfxContext* ctx = aContext->ThebesContext();
   nsPresContext *presContext = aFrame->PresContext();
 
--- a/widget/gtk/nsNativeThemeGTK.h
+++ b/widget/gtk/nsNativeThemeGTK.h
@@ -69,16 +69,17 @@ public:
                                              uint8_t aWidgetType) override;
 
   nsNativeThemeGTK();
 
 protected:
   virtual ~nsNativeThemeGTK();
 
 private:
+  GtkTextDirection GetTextDirection(nsIFrame* aFrame);
   gint GetTabMarginPixels(nsIFrame* aFrame);
   bool GetGtkWidgetAndState(uint8_t aWidgetType, nsIFrame* aFrame,
                             WidgetNodeType& aGtkWidgetType,
                             GtkWidgetState* aState, gint* aWidgetFlags);
   bool GetExtraSizeForWidget(nsIFrame* aFrame, uint8_t aWidgetType,
                                nsIntMargin* aExtra);
 
   void RefreshWidgetWindow(nsIFrame* aFrame);
--- a/widget/nsNativeTheme.cpp
+++ b/widget/nsNativeTheme.cpp
@@ -371,17 +371,17 @@ nsNativeTheme::IsDisabled(nsIFrame* aFra
 
   // For XML/XUL elements, an attribute must be equal to the literal
   // string "true" to be counted as true.  An empty string should _not_
   // be counted as true.
   return content->AttrValueIs(kNameSpaceID_None, nsGkAtoms::disabled,
                               NS_LITERAL_STRING("true"), eCaseMatters);
 }
 
-bool
+/* static */ bool
 nsNativeTheme::IsFrameRTL(nsIFrame* aFrame)
 {
   if (!aFrame) {
     return false;
   }
   WritingMode wm = aFrame->GetWritingMode();
   return !(wm.IsVertical() ? wm.IsVerticalLR() : wm.IsBidiLTR());
 }
--- a/widget/nsNativeTheme.h
+++ b/widget/nsNativeTheme.h
@@ -55,17 +55,17 @@ class nsNativeTheme : public nsITimerCal
   bool IsWidgetStyled(nsPresContext* aPresContext, nsIFrame* aFrame,
                         uint8_t aWidgetType);                                              
 
   // Accessors to widget-specific state information
 
   bool IsDisabled(nsIFrame* aFrame, mozilla::EventStates aEventStates);
 
   // RTL chrome direction
-  bool IsFrameRTL(nsIFrame* aFrame);
+  static bool IsFrameRTL(nsIFrame* aFrame);
 
   bool IsHTMLContent(nsIFrame *aFrame);
   
   // button:
   bool IsDefaultButton(nsIFrame* aFrame) {
     return CheckBooleanAttr(aFrame, nsGkAtoms::_default);
   }