Bug 871590 - Make unified titlebar / toolbar handling more robust. r=roc

This commit is contained in:
Markus Stange 2013-05-22 11:50:57 +02:00
Родитель e77f2f2de0
Коммит df0daeb0fd
7 изменённых файлов: 62 добавлений и 40 удалений

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

@ -1567,7 +1567,8 @@ nsDisplayBackgroundImage::nsDisplayBackgroundImage(nsDisplayListBuilder* aBuilde
mFrame->IsThemed(disp, &mThemeTransparency);
// Perform necessary RegisterThemeGeometry
if (disp->mAppearance == NS_THEME_MOZ_MAC_UNIFIED_TOOLBAR ||
disp->mAppearance == NS_THEME_TOOLBAR) {
disp->mAppearance == NS_THEME_TOOLBAR ||
disp->mAppearance == NS_THEME_WINDOW_TITLEBAR) {
RegisterThemeGeometry(aBuilder, aFrame);
} else if (disp->mAppearance == NS_THEME_WIN_BORDERLESS_GLASS ||
disp->mAppearance == NS_THEME_WIN_GLASS) {

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

@ -454,11 +454,11 @@ public:
* Notifies the builder that a particular themed widget exists
* at the given rectangle within the currently built display list.
* For certain appearance values (currently only
* NS_THEME_MOZ_MAC_UNIFIED_TOOLBAR and NS_THEME_TOOLBAR) this gets
* called during every display list construction, for every themed widget of
* the right type within the display list, except for themed widgets which
* are transformed or have effects applied to them (e.g. CSS opacity or
* filters).
* NS_THEME_MOZ_MAC_UNIFIED_TOOLBAR, NS_THEME_TOOLBAR and
* NS_THEME_WINDOW_TITLEBAR) this gets called during every display list
* construction, for every themed widget of the right type within the
* display list, except for themed widgets which are transformed or have
* effects applied to them (e.g. CSS opacity or filters).
*
* @param aWidgetType the -moz-appearance value for the themed widget
* @param aRect the device-pixel rect relative to the widget's displayRoot

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

@ -2072,32 +2072,58 @@ nsChildView::MaybeDrawRoundedBottomCorners(GLManager* aManager, nsIntRect aRect)
LOCAL_GL_ONE, LOCAL_GL_ONE);
}
static int32_t
FindTitlebarBottom(const nsTArray<nsIWidget::ThemeGeometry>& aThemeGeometries,
int32_t aWindowWidth)
{
int32_t titlebarBottom = 0;
for (uint32_t i = 0; i < aThemeGeometries.Length(); ++i) {
const nsIWidget::ThemeGeometry& g = aThemeGeometries[i];
if ((g.mWidgetType == NS_THEME_WINDOW_TITLEBAR) &&
g.mRect.X() <= 0 &&
g.mRect.XMost() >= aWindowWidth &&
g.mRect.Y() <= 0) {
titlebarBottom = std::max(titlebarBottom, g.mRect.YMost());
}
}
return titlebarBottom;
}
static int32_t
FindUnifiedToolbarBottom(const nsTArray<nsIWidget::ThemeGeometry>& aThemeGeometries,
int32_t aWindowWidth, int32_t aTitlebarBottom)
{
int32_t unifiedToolbarBottom = aTitlebarBottom;
for (uint32_t i = 0; i < aThemeGeometries.Length(); ++i) {
const nsIWidget::ThemeGeometry& g = aThemeGeometries[i];
if ((g.mWidgetType == NS_THEME_MOZ_MAC_UNIFIED_TOOLBAR ||
g.mWidgetType == NS_THEME_TOOLBAR) &&
g.mRect.X() <= 0 &&
g.mRect.XMost() >= aWindowWidth &&
g.mRect.Y() <= aTitlebarBottom) {
unifiedToolbarBottom = std::max(unifiedToolbarBottom, g.mRect.YMost());
}
}
return unifiedToolbarBottom;
}
void
nsChildView::UpdateThemeGeometries(const nsTArray<ThemeGeometry>& aThemeGeometries)
{
if (![mView window] || ![[mView window] isKindOfClass:[ToolbarWindow class]])
return;
int32_t windowWidth = mBounds.width;
int32_t titlebarBottom = FindTitlebarBottom(aThemeGeometries, windowWidth);
int32_t unifiedToolbarBottom =
FindUnifiedToolbarBottom(aThemeGeometries, windowWidth, titlebarBottom);
ToolbarWindow* win = (ToolbarWindow*)[mView window];
bool drawsContentsIntoWindowFrame = [win drawsContentsIntoWindowFrame];
int32_t windowWidth = mBounds.width;
int32_t titlebarHeight = CocoaPointsToDevPixels([win titlebarHeight]);
int32_t underTitlebarPos = drawsContentsIntoWindowFrame ? titlebarHeight : 0;
int32_t unifiedToolbarBottom = 0;
for (uint32_t i = 0; i < aThemeGeometries.Length(); ++i) {
const ThemeGeometry& g = aThemeGeometries[i];
if ((g.mWidgetType == NS_THEME_MOZ_MAC_UNIFIED_TOOLBAR ||
g.mWidgetType == NS_THEME_TOOLBAR) &&
g.mRect.X() <= 0 &&
g.mRect.XMost() >= windowWidth &&
g.mRect.Y() <= underTitlebarPos) {
unifiedToolbarBottom = g.mRect.YMost();
}
}
CGFloat unifiedHeight = DevPixelsToCocoaPoints(titlebarHeight + unifiedToolbarBottom - underTitlebarPos);
[win setUnifiedToolbarHeight:unifiedHeight];
int32_t contentOffset = drawsContentsIntoWindowFrame ? titlebarHeight : 0;
int32_t devUnifiedHeight = titlebarHeight + unifiedToolbarBottom - contentOffset;
[win setUnifiedToolbarHeight:DevPixelsToCocoaPoints(devUnifiedHeight)];
}
NS_IMETHODIMP

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

@ -179,15 +179,15 @@ typedef struct _nsCocoaWindowList {
@interface ToolbarWindow : BaseWindow
{
TitlebarAndBackgroundColor *mColor;
float mUnifiedToolbarHeight;
CGFloat mUnifiedToolbarHeight;
NSColor *mBackgroundColor;
NSView *mTitlebarView; // strong
}
// Pass nil here to get the default appearance.
- (void)setTitlebarColor:(NSColor*)aColor forActiveWindow:(BOOL)aActive;
- (void)setUnifiedToolbarHeight:(float)aHeight;
- (float)unifiedToolbarHeight;
- (float)titlebarHeight;
- (void)setUnifiedToolbarHeight:(CGFloat)aHeight;
- (CGFloat)unifiedToolbarHeight;
- (CGFloat)titlebarHeight;
- (NSRect)titlebarRect;
- (void)setTitlebarNeedsDisplayInRect:(NSRect)aRect sync:(BOOL)aSync;
- (void)setTitlebarNeedsDisplayInRect:(NSRect)aRect;

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

@ -2947,19 +2947,19 @@ static const NSString* kStateShowsToolbarButton = @"showsToolbarButton";
}
// Returns the unified height of titlebar + toolbar.
- (float)unifiedToolbarHeight
- (CGFloat)unifiedToolbarHeight
{
return mUnifiedToolbarHeight;
}
- (float)titlebarHeight
- (CGFloat)titlebarHeight
{
NSRect frameRect = [self frame];
return frameRect.size.height - [self contentRectForFrameRect:frameRect].size.height;
}
// Stores the complete height of titlebar + toolbar.
- (void)setUnifiedToolbarHeight:(float)aHeight
- (void)setUnifiedToolbarHeight:(CGFloat)aHeight
{
if (aHeight == mUnifiedToolbarHeight)
return;
@ -3154,7 +3154,7 @@ static const NSString* kStateShowsToolbarButton = @"showsToolbarButton";
static void
DrawNativeTitlebar(CGContextRef aContext, CGRect aTitlebarRect,
float aUnifiedToolbarHeight, BOOL aIsMain)
CGFloat aUnifiedToolbarHeight, BOOL aIsMain)
{
if (aTitlebarRect.size.width * aTitlebarRect.size.height > CUIDRAW_MAX_AREA) {
return;
@ -3165,7 +3165,7 @@ DrawNativeTitlebar(CGContextRef aContext, CGRect aTitlebarRect,
@"kCUIWidgetWindowFrame", @"widget",
@"regularwin", @"windowtype",
(aIsMain ? @"normal" : @"inactive"), @"state",
[NSNumber numberWithInt:aUnifiedToolbarHeight], @"kCUIWindowFrameUnifiedTitleBarHeightKey",
[NSNumber numberWithDouble:aUnifiedToolbarHeight], @"kCUIWindowFrameUnifiedTitleBarHeightKey",
[NSNumber numberWithBool:YES], @"kCUIWindowFrameDrawTitleSeparatorKey",
nil],
nil);

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

@ -109,7 +109,7 @@ protected:
void DrawStatusBar(CGContextRef cgContext, const HIRect& inBoxRect,
nsIFrame *aFrame);
void DrawNativeTitlebar(CGContextRef aContext, CGRect aTitlebarRect,
float aUnifiedHeight, BOOL aIsMain);
CGFloat aUnifiedHeight, BOOL aIsMain);
void DrawResizer(CGContextRef cgContext, const HIRect& aRect, nsIFrame *aFrame);
// Scrollbars

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

@ -1795,14 +1795,9 @@ ToolbarCanBeUnified(CGContextRef cgContext, const HIRect& inBoxRect, NSWindow* a
ToolbarWindow* win = (ToolbarWindow*)aWindow;
float unifiedToolbarHeight = [win unifiedToolbarHeight];
float titlebarHeight = [win titlebarHeight];
bool drawsContentsIntoWindowFrame = [win drawsContentsIntoWindowFrame];
float underTitlebarPos = drawsContentsIntoWindowFrame ? titlebarHeight : 0;
return inBoxRect.origin.x == 0 &&
inBoxRect.size.width >= [win frame].size.width &&
inBoxRect.origin.y <= underTitlebarPos &&
floor(inBoxRect.origin.y + inBoxRect.size.height) <= unifiedToolbarHeight;
CGRectGetMaxY(inBoxRect) <= unifiedToolbarHeight;
}
void
@ -1876,7 +1871,7 @@ nsNativeThemeCocoa::DrawStatusBar(CGContextRef cgContext, const HIRect& inBoxRec
void
nsNativeThemeCocoa::DrawNativeTitlebar(CGContextRef aContext, CGRect aTitlebarRect,
float aUnifiedHeight, BOOL aIsMain)
CGFloat aUnifiedHeight, BOOL aIsMain)
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;