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

--HG--
extra : rebase_source : 1bfafdb24f7d6df0ad2552b786b8af84b71cc28a
This commit is contained in:
Makoto Kato 2016-05-26 23:39:50 +09:00
Родитель a8515958d7
Коммит 15b6b9d8df
3 изменённых файлов: 44 добавлений и 0 удалений

Просмотреть файл

@ -2880,6 +2880,36 @@ nsChildView::DispatchAPZWheelInputEvent(InputData& aEvent, bool aCanTriggerSwipe
} }
} }
// 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 void
nsChildView::LookUpDictionary( nsChildView::LookUpDictionary(
const nsAString& aText, const nsAString& aText,
@ -2904,6 +2934,8 @@ nsChildView::LookUpDictionary(
pt.y += [font ascender]; pt.y += [font ascender];
} }
} }
AutoBackgroundSetter setter(mView);
[mView showDefinitionForAttributedString:attrStr atPoint:pt]; [mView showDefinitionForAttributedString:attrStr atPoint:pt];
NS_OBJC_END_TRY_ABORT_BLOCK; NS_OBJC_END_TRY_ABORT_BLOCK;

Просмотреть файл

@ -241,6 +241,8 @@ typedef struct _nsCocoaWindowList {
- (void)placeFullScreenButton:(NSRect)aRect; - (void)placeFullScreenButton:(NSRect)aRect;
- (NSPoint)windowButtonsPositionWithDefaultPosition:(NSPoint)aDefaultPosition; - (NSPoint)windowButtonsPositionWithDefaultPosition:(NSPoint)aDefaultPosition;
- (NSPoint)fullScreenButtonPositionWithDefaultPosition:(NSPoint)aDefaultPosition; - (NSPoint)fullScreenButtonPositionWithDefaultPosition:(NSPoint)aDefaultPosition;
- (void)setTemporaryBackgroundColor;
- (void)restoreBackgroundColor;
@end @end
class nsCocoaWindow : public nsBaseWidget, public nsPIWidgetCocoa class nsCocoaWindow : public nsBaseWidget, public nsPIWidgetCocoa

Просмотреть файл

@ -3401,6 +3401,16 @@ static const NSString* kStateCollectionBehavior = @"collectionBehavior";
return mBackgroundColor; return mBackgroundColor;
} }
- (void)setTemporaryBackgroundColor
{
[super setBackgroundColor:[NSColor whiteColor]];
}
- (void)restoreBackgroundColor
{
[super setBackgroundColor:mBackgroundColor];
}
- (void)setTitlebarNeedsDisplayInRect:(NSRect)aRect - (void)setTitlebarNeedsDisplayInRect:(NSRect)aRect
{ {
[self setTitlebarNeedsDisplayInRect:aRect sync:NO]; [self setTitlebarNeedsDisplayInRect:aRect sync:NO];