Bug 1212527 - Set background color to NSColor before calling showDefinitionForAttributedString on 10.11. r=mstange
☠☠ backed out by 1bb60897b5e1 ☠ ☠
authorMakoto Kato <m_kato@ga2.so-net.ne.jp>
Thu, 26 May 2016 23:39:50 +0900
changeset 338196 d89f93a40f78e80b86d952237e2813a3f43e6317
parent 338195 94033f5e655567162a397af1f48a3bf00e884421
child 338197 83c87ecd3700a61d0310648628cd5a58935dc6a0
push id6249
push userjlund@mozilla.com
push dateMon, 01 Aug 2016 13:59:36 +0000
treeherdermozilla-beta@bad9d4f5bf7e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmstange
bugs1212527
milestone49.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 1212527 - Set background color to NSColor before calling showDefinitionForAttributedString on 10.11. r=mstange When calling showDefinitionforAttributedString on OSX 10.11, it always return error due to the following exception. Exception: decodeObjectForKey: class "TitlebarAndBackgroundColor" not loaded or does not exist So before calling it, we set temporary color value, then restore color after calling it. MozReview-Commit-ID: 1YeY6X1W6AV
widget/cocoa/nsChildView.mm
widget/cocoa/nsCocoaWindow.h
widget/cocoa/nsCocoaWindow.mm
--- a/widget/cocoa/nsChildView.mm
+++ b/widget/cocoa/nsChildView.mm
@@ -2875,16 +2875,46 @@ nsChildView::DispatchAPZWheelInputEvent(
       return;
   }
   if (event.mMessage == eWheel &&
       (event.mDeltaX != 0 || event.mDeltaY != 0)) {
     DispatchEvent(&event, status);
   }
 }
 
+// When using 10.11, calling showDefinitionForAttributedString causes the
+// following exception on LookupViewService. (rdar://26476091)
+//
+// Exception: decodeObjectForKey: class "TitlebarAndBackgroundColor" not
+// loaded or does not exist
+//
+// So we set temporary color that is NSColor before calling it.
+
+class MOZ_RAII AutoBackgroundSetter final {
+public:
+  AutoBackgroundSetter(NSView* aView) {
+    if (nsCocoaFeatures::OnElCapitanOrLater() &&
+        [[aView window] isKindOfClass:[ToolbarWindow class]]) {
+      mWindow = (ToolbarWindow*)[aView window];
+      [mWindow setTemporaryBackgroundColor];
+    } else {
+      mWindow = nullptr;
+    }
+  }
+
+  ~AutoBackgroundSetter() {
+    if (mWindow) {
+      [mWindow restoreBackgroundColor];
+    }
+  }
+
+private:
+  ToolbarWindow* mWindow;
+};
+
 void
 nsChildView::LookUpDictionary(
                const nsAString& aText,
                const nsTArray<mozilla::FontRange>& aFontRangeArray,
                const bool aIsVertical,
                const LayoutDeviceIntPoint& aPoint)
 {
   NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
@@ -2899,16 +2929,18 @@ nsChildView::LookUpDictionary(
   NSFont* font = [attributes objectForKey:NSFontAttributeName];
   if (font) {
     if (aIsVertical) {
       pt.x -= [font descender];
     } else {
       pt.y += [font ascender];
     }
   }
+
+  AutoBackgroundSetter setter(mView);
   [mView showDefinitionForAttributedString:attrStr atPoint:pt];
 
   NS_OBJC_END_TRY_ABORT_BLOCK;
 }
 
 #ifdef ACCESSIBILITY
 already_AddRefed<a11y::Accessible>
 nsChildView::GetDocumentAccessible()
--- a/widget/cocoa/nsCocoaWindow.h
+++ b/widget/cocoa/nsCocoaWindow.h
@@ -236,16 +236,18 @@ typedef struct _nsCocoaWindowList {
 - (void)setTitlebarNeedsDisplayInRect:(NSRect)aRect sync:(BOOL)aSync;
 - (void)setTitlebarNeedsDisplayInRect:(NSRect)aRect;
 - (void)setDrawsContentsIntoWindowFrame:(BOOL)aState;
 - (void)setSheetAttachmentPosition:(CGFloat)aY;
 - (void)placeWindowButtons:(NSRect)aRect;
 - (void)placeFullScreenButton:(NSRect)aRect;
 - (NSPoint)windowButtonsPositionWithDefaultPosition:(NSPoint)aDefaultPosition;
 - (NSPoint)fullScreenButtonPositionWithDefaultPosition:(NSPoint)aDefaultPosition;
+- (void)setTemporaryBackgroundColor;
+- (void)restoreBackgroundColor;
 @end
 
 class nsCocoaWindow : public nsBaseWidget, public nsPIWidgetCocoa
 {
 private:
   typedef nsBaseWidget Inherited;
 
 public:
--- a/widget/cocoa/nsCocoaWindow.mm
+++ b/widget/cocoa/nsCocoaWindow.mm
@@ -3396,16 +3396,26 @@ static const NSString* kStateCollectionB
   mBackgroundColor = aColor;
 }
 
 - (NSColor*)windowBackgroundColor
 {
   return mBackgroundColor;
 }
 
+- (void)setTemporaryBackgroundColor
+{
+  [super setBackgroundColor:[NSColor whiteColor]];
+}
+
+- (void)restoreBackgroundColor
+{
+  [super setBackgroundColor:mBackgroundColor];
+}
+
 - (void)setTitlebarNeedsDisplayInRect:(NSRect)aRect
 {
   [self setTitlebarNeedsDisplayInRect:aRect sync:NO];
 }
 
 - (void)setTitlebarNeedsDisplayInRect:(NSRect)aRect sync:(BOOL)aSync
 {
   NSRect titlebarRect = [self titlebarRect];