Bug 863104 - Fix Dock progress drawing on 10.6. r=josh
authorDave Vasilevsky <dave@vasilevsky.ca>
Wed, 17 Apr 2013 02:51:52 -0400
changeset 140814 63a501b7c61d89b9602df876931f02973486e672
parent 140813 dba3bdd9fe8855411ebc290480f0ae0d4f927a8a
child 140815 eeb9d7a408ab1595941fc2aa56719cced5badefe
push id2579
push userakeybl@mozilla.com
push dateMon, 24 Jun 2013 18:52:47 +0000
treeherdermozilla-beta@b69b7de8a05a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjosh
bugs863104
milestone23.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 863104 - Fix Dock progress drawing on 10.6. r=josh
widget/cocoa/nsMacDockSupport.h
widget/cocoa/nsMacDockSupport.mm
widget/cocoa/nsNativeThemeCocoa.h
--- a/widget/cocoa/nsMacDockSupport.h
+++ b/widget/cocoa/nsMacDockSupport.h
@@ -1,40 +1,40 @@
 /* -*- Mode: c++; tab-width: 2; indent-tabs-mode: nil; -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
-#import <Carbon/Carbon.h>
-
 #include "nsIMacDockSupport.h"
 #include "nsIStandaloneNativeMenu.h"
 #include "nsITaskbarProgress.h"
 #include "nsITimer.h"
 #include "nsCOMPtr.h"
 #include "nsString.h"
+#include "nsNativeThemeCocoa.h"
 
 class nsMacDockSupport : public nsIMacDockSupport, public nsITaskbarProgress
 {
 public:
   nsMacDockSupport();
   virtual ~nsMacDockSupport();
 
   NS_DECL_ISUPPORTS
   NS_DECL_NSIMACDOCKSUPPORT
   NS_DECL_NSITASKBARPROGRESS
 
 protected:
   nsCOMPtr<nsIStandaloneNativeMenu> mDockMenu;
   nsString mBadgeText;
 
   NSImage *mAppIcon, *mProgressBackground;
-  HIThemeTrackDrawInfo mProgressDrawInfo;
 
+  HIRect mProgressBounds;
   nsTaskbarProgressState mProgressState;
   double mProgressFraction;
   nsCOMPtr<nsITimer> mProgressTimer;
+  nsRefPtr<nsNativeThemeCocoa> mTheme;
 
   static void RedrawIconCallback(nsITimer* aTimer, void* aClosure);
 
   bool InitProgress();
   nsresult RedrawIcon();
 };
--- a/widget/cocoa/nsMacDockSupport.mm
+++ b/widget/cocoa/nsMacDockSupport.mm
@@ -1,14 +1,13 @@
 /* -*- Mode: c++; tab-width: 2; indent-tabs-mode: nil; -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
-#import <Carbon/Carbon.h>
 #import <Cocoa/Cocoa.h>
 
 #include "nsComponentManagerUtils.h"
 #include "nsMacDockSupport.h"
 #include "nsObjCExceptions.h"
 
 NS_IMPL_ISUPPORTS2(nsMacDockSupport, nsIMacDockSupport, nsITaskbarProgress)
 
@@ -134,69 +133,43 @@ bool nsMacDockSupport::InitProgress()
   if (mProgressState != STATE_NORMAL && mProgressState != STATE_INDETERMINATE) {
     return false;
   }
 
   if (!mAppIcon) {
     mProgressTimer = do_CreateInstance(NS_TIMER_CONTRACTID);
     mAppIcon = [[NSImage imageNamed:@"NSApplicationIcon"] retain];
     mProgressBackground = [mAppIcon copyWithZone:nil];
+    mTheme = new nsNativeThemeCocoa();
 
     NSSize sz = [mProgressBackground size];
-    mProgressDrawInfo.version = 0;
-    mProgressDrawInfo.min = 0;
-    mProgressDrawInfo.value = 0;
-    mProgressDrawInfo.max = PR_INT32_MAX;
-    mProgressDrawInfo.bounds = CGRectMake(sz.width * 1/32, sz.height * 3/32,
-                                          sz.width * 30/32, sz.height * 2/32);
-    mProgressDrawInfo.attributes = kThemeTrackHorizontal;
-    mProgressDrawInfo.enableState = kThemeTrackActive;
-    mProgressDrawInfo.kind = kThemeLargeProgressBar;
-    mProgressDrawInfo.trackInfo.progress.phase = 0;
-
-    // Draw a light background, to visually distinguish the progress.
-    HIRect bounds;
-    HIThemeGetTrackBounds(&mProgressDrawInfo, &bounds);
-    // Margins within track, empirically. FIXME: Don't hardcode?
-    int mleft = 3, mtop = 3, mright = 3, mbot = 1;
-    bounds.origin.x += mleft;
-    bounds.origin.y += mbot;
-    bounds.size.width -= mleft + mright;
-    bounds.size.height -= mtop + mbot;
-
+    mProgressBounds = CGRectMake(sz.width * 1/32, sz.height * 3/32,
+                                 sz.width * 30/32, sz.height * 4/32);
     [mProgressBackground lockFocus];
     [[NSColor whiteColor] set];
-    NSRectFill(NSRectFromCGRect(bounds));
+    NSRectFill(NSRectFromCGRect(mProgressBounds));
     [mProgressBackground unlockFocus];
   }
   return true;
 }
 
 nsresult
 nsMacDockSupport::RedrawIcon()
 {
   NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
 
   if (InitProgress()) {
-    // TODO: - Share code with nsNativeThemeCocoa?
-    //       - Implement ERROR and PAUSED states?
+    // TODO: - Implement ERROR and PAUSED states?
     NSImage *icon = [mProgressBackground copyWithZone:nil];
-
     bool isIndeterminate = (mProgressState != STATE_NORMAL);
-    mProgressDrawInfo.value = PR_INT32_MAX * mProgressFraction;
-    mProgressDrawInfo.kind = isIndeterminate ? kThemeLargeIndeterminateBar
-                                             : kThemeLargeProgressBar;
-
-    int stepsPerSecond = isIndeterminate ? 60 : 30;
-    mProgressDrawInfo.trackInfo.progress.phase =
-      uint8_t(PR_IntervalToMilliseconds(PR_IntervalNow()) * stepsPerSecond / 1000);
 
     [icon lockFocus];
     CGContextRef ctx = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];
-    HIThemeDrawTrack(&mProgressDrawInfo, NULL, ctx, kHIThemeOrientationNormal);
+    mTheme->DrawProgress(ctx, mProgressBounds, isIndeterminate,
+      true, mProgressFraction, 1.0, NULL);
     [icon unlockFocus];
     [NSApp setApplicationIconImage:icon];
     [icon release];
   } else {
     [NSApp setApplicationIconImage:mAppIcon];
   }
 
   return NS_OK;
--- a/widget/cocoa/nsNativeThemeCocoa.h
+++ b/widget/cocoa/nsNativeThemeCocoa.h
@@ -56,30 +56,31 @@ public:
                                 nsIAtom* aAttribute, bool* aShouldRepaint);
   NS_IMETHOD ThemeChanged();
   bool ThemeSupportsWidget(nsPresContext* aPresContext, nsIFrame* aFrame, uint8_t aWidgetType);
   bool WidgetIsContainer(uint8_t aWidgetType);
   bool ThemeDrawsFocusForWidget(nsPresContext* aPresContext, nsIFrame* aFrame, uint8_t aWidgetType);
   bool ThemeNeedsComboboxDropmarker();
   virtual Transparency GetWidgetTransparency(nsIFrame* aFrame, uint8_t aWidgetType);
 
+  void DrawProgress(CGContextRef context, const HIRect& inBoxRect,
+                    bool inIsIndeterminate, bool inIsHorizontal,
+                    double inValue, double inMaxValue, nsIFrame* aFrame);
+
 protected:  
 
   nsIntMargin RTLAwareMargin(const nsIntMargin& aMargin, nsIFrame* aFrame);
   nsIFrame* SeparatorResponsibility(nsIFrame* aBefore, nsIFrame* aAfter);
   CGRect SeparatorAdjustedRect(CGRect aRect, nsIFrame* aLeft,
                                nsIFrame* aCurrent, nsIFrame* aRight);
 
   // HITheme drawing routines
   void DrawFrame(CGContextRef context, HIThemeFrameKind inKind,
                  const HIRect& inBoxRect, bool inReadOnly,
                  nsEventStates inState);
-  void DrawProgress(CGContextRef context, const HIRect& inBoxRect,
-                    bool inIsIndeterminate, bool inIsHorizontal,
-                    double inValue, double inMaxValue, nsIFrame* aFrame);
   void DrawMeter(CGContextRef context, const HIRect& inBoxRect,
                  nsIFrame* aFrame);
   void DrawSegment(CGContextRef cgContext, const HIRect& inBoxRect,
                    nsEventStates inState, nsIFrame* aFrame,
                    const SegmentedControlRenderSettings& aSettings);
   void DrawTabPanel(CGContextRef context, const HIRect& inBoxRect, nsIFrame* aFrame);
   void DrawScale(CGContextRef context, const HIRect& inBoxRect,
                  nsEventStates inState, bool inDirection,