Bug 1096093 - Have Cocoa widget backend cache overlay scrollbar metrics. r=mstange.

--HG--
extra : rebase_source : fe44034cfbf4fe992a2adc56dc30864cc631cfa1
This commit is contained in:
Mike Conley 2015-04-22 10:58:48 -04:00
parent f83673f8f9
commit 8975d0730c
2 changed files with 76 additions and 3 deletions

View File

@ -26,6 +26,10 @@ public:
static bool UseOverlayScrollbars();
virtual nsTArray<LookAndFeelInt> GetIntCacheImpl();
virtual void SetIntCacheImpl(const nsTArray<LookAndFeelInt>& lookAndFeelIntCache);
virtual void RefreshImpl();
protected:
// Apple hasn't defined a constant for scollbars with two arrows on each end, so we'll use this one.
@ -34,6 +38,13 @@ protected:
static bool SystemWantsOverlayScrollbars();
static bool AllowOverlayScrollbarsOverlap();
private:
int32_t mUseOverlayScrollbars;
bool mUseOverlayScrollbarsCached;
int32_t mAllowOverlayScrollbarsOverlap;
bool mAllowOverlayScrollbarsOverlapCached;
};
#endif // nsLookAndFeel_h_

View File

@ -12,6 +12,7 @@
#include "gfxFont.h"
#include "gfxFontConstants.h"
#include "mozilla/gfx/2D.h"
#include "mozilla/widget/WidgetMessageUtils.h"
#import <Cocoa/Cocoa.h>
@ -28,7 +29,12 @@ typedef NSInteger mozNSScrollerStyle;
+ (mozNSScrollerStyle)preferredScrollerStyle;
@end
nsLookAndFeel::nsLookAndFeel() : nsXPLookAndFeel()
nsLookAndFeel::nsLookAndFeel()
: nsXPLookAndFeel()
, mUseOverlayScrollbars(-1)
, mUseOverlayScrollbarsCached(false)
, mAllowOverlayScrollbarsOverlap(-1)
, mAllowOverlayScrollbarsOverlapCached(false)
{
}
@ -359,10 +365,18 @@ nsLookAndFeel::GetIntImpl(IntID aID, int32_t &aResult)
aResult = eScrollThumbStyle_Proportional;
break;
case eIntID_UseOverlayScrollbars:
aResult = SystemWantsOverlayScrollbars() ? 1 : 0;
if (!mUseOverlayScrollbarsCached) {
mUseOverlayScrollbars = SystemWantsOverlayScrollbars() ? 1 : 0;
mUseOverlayScrollbarsCached = true;
}
aResult = mUseOverlayScrollbars;
break;
case eIntID_AllowOverlayScrollbarsOverlap:
aResult = AllowOverlayScrollbarsOverlap() ? 1 : 0;
if (!mAllowOverlayScrollbarsOverlapCached) {
mAllowOverlayScrollbarsOverlap = AllowOverlayScrollbarsOverlap() ? 1 : 0;
mAllowOverlayScrollbarsOverlapCached = true;
}
aResult = mAllowOverlayScrollbarsOverlap;
break;
case eIntID_ScrollbarDisplayOnMouseMove:
aResult = 0;
@ -633,3 +647,51 @@ nsLookAndFeel::GetFontImpl(FontID aID, nsString &aFontName,
NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(false);
}
nsTArray<LookAndFeelInt>
nsLookAndFeel::GetIntCacheImpl()
{
nsTArray<LookAndFeelInt> lookAndFeelIntCache =
nsXPLookAndFeel::GetIntCacheImpl();
LookAndFeelInt useOverlayScrollbars;
useOverlayScrollbars.id = eIntID_UseOverlayScrollbars;
useOverlayScrollbars.value = GetInt(eIntID_UseOverlayScrollbars);
lookAndFeelIntCache.AppendElement(useOverlayScrollbars);
LookAndFeelInt allowOverlayScrollbarsOverlap;
allowOverlayScrollbarsOverlap.id = eIntID_AllowOverlayScrollbarsOverlap;
allowOverlayScrollbarsOverlap.value = GetInt(eIntID_AllowOverlayScrollbarsOverlap);
lookAndFeelIntCache.AppendElement(allowOverlayScrollbarsOverlap);
return lookAndFeelIntCache;
}
void
nsLookAndFeel::SetIntCacheImpl(const nsTArray<LookAndFeelInt>& lookAndFeelIntCache)
{
for (auto entry : lookAndFeelIntCache) {
switch(entry.id) {
case eIntID_UseOverlayScrollbars:
mUseOverlayScrollbars = entry.value;
mUseOverlayScrollbarsCached = true;
break;
case eIntID_AllowOverlayScrollbarsOverlap:
mAllowOverlayScrollbarsOverlap = entry.value;
mAllowOverlayScrollbarsOverlapCached = true;
break;
}
}
}
void
nsLookAndFeel::RefreshImpl()
{
// We should only clear the cache if we're in the main browser process.
// Otherwise, we should wait for the parent to inform us of new values
// to cache via LookAndFeel::SetIntCache.
if (XRE_GetProcessType() == GeckoProcessType_Default) {
mUseOverlayScrollbarsCached = false;
mAllowOverlayScrollbarsOverlapCached = false;
}
}