2007-03-22 10:30:00 -07:00
|
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
|
/* 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/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
|
|
#include "nsNativeThemeCocoa.h"
|
2008-02-20 17:01:27 -08:00
|
|
|
|
#include "nsObjCExceptions.h"
|
2013-12-05 08:20:34 -08:00
|
|
|
|
#include "nsNumberControlFrame.h"
|
2013-03-15 22:40:15 -07:00
|
|
|
|
#include "nsRangeFrame.h"
|
2011-04-07 18:04:40 -07:00
|
|
|
|
#include "nsRenderingContext.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
#include "nsRect.h"
|
|
|
|
|
#include "nsSize.h"
|
|
|
|
|
#include "nsThemeConstants.h"
|
|
|
|
|
#include "nsIPresShell.h"
|
|
|
|
|
#include "nsPresContext.h"
|
|
|
|
|
#include "nsIContent.h"
|
|
|
|
|
#include "nsIDocument.h"
|
|
|
|
|
#include "nsIFrame.h"
|
|
|
|
|
#include "nsIAtom.h"
|
2014-02-27 15:04:46 -08:00
|
|
|
|
#include "nsNameSpaceManager.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
#include "nsPresContext.h"
|
2011-10-14 11:11:22 -07:00
|
|
|
|
#include "nsGkAtoms.h"
|
2012-05-17 00:53:20 -07:00
|
|
|
|
#include "nsCocoaFeatures.h"
|
2008-09-16 01:21:06 -07:00
|
|
|
|
#include "nsCocoaWindow.h"
|
2008-10-15 06:01:10 -07:00
|
|
|
|
#include "nsNativeThemeColors.h"
|
2010-06-21 05:37:35 -07:00
|
|
|
|
#include "nsIScrollableFrame.h"
|
2014-04-02 21:18:36 -07:00
|
|
|
|
#include "mozilla/EventStates.h"
|
2012-06-06 00:56:28 -07:00
|
|
|
|
#include "mozilla/dom/Element.h"
|
2013-08-01 15:24:24 -07:00
|
|
|
|
#include "mozilla/dom/HTMLMeterElement.h"
|
2013-05-02 07:58:00 -07:00
|
|
|
|
#include "nsLookAndFeel.h"
|
2014-08-27 17:15:33 -07:00
|
|
|
|
#include "VibrancyManager.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
|
|
#include "gfxContext.h"
|
|
|
|
|
#include "gfxQuartzSurface.h"
|
2008-02-20 03:33:27 -08:00
|
|
|
|
#include "gfxQuartzNativeDrawing.h"
|
2013-01-15 04:22:03 -08:00
|
|
|
|
#include <algorithm>
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
2014-04-02 21:18:36 -07:00
|
|
|
|
using namespace mozilla;
|
2013-07-12 14:19:28 -07:00
|
|
|
|
using namespace mozilla::gfx;
|
2013-08-01 15:24:24 -07:00
|
|
|
|
using mozilla::dom::HTMLMeterElement;
|
2013-07-12 14:19:28 -07:00
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
|
#define DRAW_IN_FRAME_DEBUG 0
|
2007-04-10 17:25:11 -07:00
|
|
|
|
#define SCROLLBARS_VISUAL_DEBUG 0
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
2007-08-07 12:36:40 -07:00
|
|
|
|
// private Quartz routines needed here
|
2007-03-22 10:30:00 -07:00
|
|
|
|
extern "C" {
|
|
|
|
|
CG_EXTERN void CGContextSetCTM(CGContextRef, CGAffineTransform);
|
2014-09-18 01:52:35 -07:00
|
|
|
|
CG_EXTERN void CGContextSetBaseCTM(CGContextRef, CGAffineTransform);
|
2014-08-27 17:15:27 -07:00
|
|
|
|
typedef CFTypeRef CUIRendererRef;
|
|
|
|
|
void CUIDraw(CUIRendererRef r, CGRect rect, CGContextRef ctx, CFDictionaryRef options, CFDictionaryRef* result);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
}
|
|
|
|
|
|
2008-10-13 09:58:40 -07:00
|
|
|
|
// Workaround for NSCell control tint drawing
|
|
|
|
|
// Without this workaround, NSCells are always drawn with the clear control tint
|
|
|
|
|
// as long as they're not attached to an NSControl which is a subview of an active window.
|
|
|
|
|
// XXXmstange Why doesn't Webkit need this?
|
|
|
|
|
@implementation NSCell (ControlTintWorkaround)
|
|
|
|
|
- (int)_realControlTint { return [self controlTint]; }
|
|
|
|
|
@end
|
|
|
|
|
|
2009-09-16 15:06:16 -07:00
|
|
|
|
// The purpose of this class is to provide objects that can be used when drawing
|
|
|
|
|
// NSCells using drawWithFrame:inView: without causing any harm. The only
|
|
|
|
|
// messages that will be sent to such an object are "isFlipped" and
|
|
|
|
|
// "currentEditor": isFlipped needs to return YES in order to avoid drawing bugs
|
|
|
|
|
// on 10.4 (see bug 465069); currentEditor (which isn't even a method of
|
|
|
|
|
// NSView) will be called when drawing search fields, and we only provide it in
|
|
|
|
|
// order to prevent "unrecognized selector" exceptions.
|
|
|
|
|
// There's no need to pass the actual NSView that we're drawing into to
|
|
|
|
|
// drawWithFrame:inView:. What's more, doing so even causes unnecessary
|
|
|
|
|
// invalidations as soon as we draw a focusring!
|
|
|
|
|
@interface CellDrawView : NSView
|
|
|
|
|
|
|
|
|
|
@end;
|
|
|
|
|
|
|
|
|
|
@implementation CellDrawView
|
|
|
|
|
|
|
|
|
|
- (BOOL)isFlipped
|
|
|
|
|
{
|
|
|
|
|
return YES;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (NSText*)currentEditor
|
|
|
|
|
{
|
|
|
|
|
return nil;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
2014-02-13 03:09:59 -08:00
|
|
|
|
static void
|
2014-08-20 08:09:44 -07:00
|
|
|
|
DrawFocusRingForCellIfNeeded(NSCell* aCell, NSRect aWithFrame, NSView* aInView)
|
2014-02-13 03:09:59 -08:00
|
|
|
|
{
|
|
|
|
|
if ([aCell showsFirstResponder]) {
|
|
|
|
|
CGContextRef cgContext = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];
|
|
|
|
|
CGContextSaveGState(cgContext);
|
|
|
|
|
|
|
|
|
|
// It's important to set the focus ring style before we enter the
|
|
|
|
|
// transparency layer so that the transparency layer only contains
|
|
|
|
|
// the normal button mask without the focus ring, and the conversion
|
|
|
|
|
// to the focus ring shape happens only when the transparency layer is
|
|
|
|
|
// ended.
|
|
|
|
|
NSSetFocusRingStyle(NSFocusRingOnly);
|
|
|
|
|
|
|
|
|
|
// We need to draw the whole button into a transparency layer because
|
|
|
|
|
// many button types are composed of multiple parts, and if these parts
|
|
|
|
|
// were drawn while the focus ring style was active, each individual part
|
|
|
|
|
// would produce a focus ring for itself. But we only want one focus ring
|
|
|
|
|
// for the whole button. The transparency layer is a way to merge the
|
|
|
|
|
// individual button parts together before the focus ring shape is
|
|
|
|
|
// calculated.
|
|
|
|
|
CGContextBeginTransparencyLayerWithRect(cgContext, NSRectToCGRect(aWithFrame), 0);
|
|
|
|
|
[aCell drawFocusRingMaskWithFrame:aWithFrame inView:aInView];
|
|
|
|
|
CGContextEndTransparencyLayer(cgContext);
|
|
|
|
|
|
|
|
|
|
CGContextRestoreGState(cgContext);
|
|
|
|
|
}
|
2014-08-20 08:09:44 -07:00
|
|
|
|
}
|
|
|
|
|
|
2014-09-18 02:17:05 -07:00
|
|
|
|
static bool
|
|
|
|
|
FocusIsDrawnByDrawWithFrame()
|
2014-08-20 08:09:44 -07:00
|
|
|
|
{
|
|
|
|
|
#if defined(MAC_OS_X_VERSION_10_8) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_8
|
|
|
|
|
// When building with the 10.8 SDK or higher, focus rings don't draw as part
|
|
|
|
|
// of -[NSCell drawWithFrame:inView:] and must be drawn by a separate call
|
|
|
|
|
// to -[NSCell drawFocusRingMaskWithFrame:inView:]; .
|
|
|
|
|
// See the NSButtonCell section under
|
|
|
|
|
// https://developer.apple.com/library/mac/releasenotes/AppKit/RN-AppKitOlderNotes/#X10_8Notes
|
2014-09-18 02:17:05 -07:00
|
|
|
|
return false;
|
|
|
|
|
#else
|
|
|
|
|
// On 10.10 and up, this is the case even when building against the 10.7 SDK
|
|
|
|
|
// or lower.
|
|
|
|
|
return !nsCocoaFeatures::OnYosemiteOrLater();
|
2014-02-13 03:09:59 -08:00
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-18 02:17:05 -07:00
|
|
|
|
static void
|
|
|
|
|
DrawCellIncludingFocusRing(NSCell* aCell, NSRect aWithFrame, NSView* aInView)
|
|
|
|
|
{
|
|
|
|
|
[aCell drawWithFrame:aWithFrame inView:aInView];
|
|
|
|
|
|
|
|
|
|
if (!FocusIsDrawnByDrawWithFrame()) {
|
|
|
|
|
DrawFocusRingForCellIfNeeded(aCell, aWithFrame, aInView);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-21 02:07:32 -07:00
|
|
|
|
/**
|
|
|
|
|
* NSProgressBarCell is used to draw progress bars of any size.
|
|
|
|
|
*/
|
|
|
|
|
@interface NSProgressBarCell : NSCell
|
|
|
|
|
{
|
|
|
|
|
/*All instance variables are private*/
|
|
|
|
|
double mValue;
|
|
|
|
|
double mMax;
|
|
|
|
|
bool mIsIndeterminate;
|
|
|
|
|
bool mIsHorizontal;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)setValue:(double)value;
|
|
|
|
|
- (double)value;
|
|
|
|
|
- (void)setMax:(double)max;
|
|
|
|
|
- (double)max;
|
|
|
|
|
- (void)setIndeterminate:(bool)aIndeterminate;
|
|
|
|
|
- (bool)isIndeterminate;
|
|
|
|
|
- (void)setHorizontal:(bool)aIsHorizontal;
|
|
|
|
|
- (bool)isHorizontal;
|
|
|
|
|
- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView;
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
@implementation NSProgressBarCell
|
|
|
|
|
|
|
|
|
|
- (void)setMax:(double)aMax
|
|
|
|
|
{
|
|
|
|
|
mMax = aMax;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (double)max
|
|
|
|
|
{
|
|
|
|
|
return mMax;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)setValue:(double)aValue
|
|
|
|
|
{
|
|
|
|
|
mValue = aValue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (double)value
|
|
|
|
|
{
|
|
|
|
|
return mValue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)setIndeterminate:(bool)aIndeterminate
|
|
|
|
|
{
|
|
|
|
|
mIsIndeterminate = aIndeterminate;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (bool)isIndeterminate
|
|
|
|
|
{
|
|
|
|
|
return mIsIndeterminate;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)setHorizontal:(bool)aIsHorizontal
|
|
|
|
|
{
|
|
|
|
|
mIsHorizontal = aIsHorizontal;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (bool)isHorizontal
|
|
|
|
|
{
|
|
|
|
|
return mIsHorizontal;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView
|
|
|
|
|
{
|
|
|
|
|
CGContext* cgContext = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];
|
|
|
|
|
|
|
|
|
|
HIThemeTrackDrawInfo tdi;
|
|
|
|
|
|
|
|
|
|
tdi.version = 0;
|
|
|
|
|
tdi.min = 0;
|
|
|
|
|
|
2012-09-27 23:57:33 -07:00
|
|
|
|
tdi.value = INT32_MAX * (mValue / mMax);
|
|
|
|
|
tdi.max = INT32_MAX;
|
2011-04-21 02:07:32 -07:00
|
|
|
|
tdi.bounds = NSRectToCGRect(cellFrame);
|
|
|
|
|
tdi.attributes = mIsHorizontal ? kThemeTrackHorizontal : 0;
|
|
|
|
|
tdi.enableState = [self controlTint] == NSClearControlTint ? kThemeTrackInactive
|
|
|
|
|
: kThemeTrackActive;
|
|
|
|
|
|
|
|
|
|
NSControlSize size = [self controlSize];
|
|
|
|
|
if (size == NSRegularControlSize) {
|
|
|
|
|
tdi.kind = mIsIndeterminate ? kThemeLargeIndeterminateBar
|
|
|
|
|
: kThemeLargeProgressBar;
|
|
|
|
|
} else {
|
|
|
|
|
NS_ASSERTION(size == NSSmallControlSize,
|
|
|
|
|
"We shouldn't have another size than small and regular for the moment");
|
|
|
|
|
tdi.kind = mIsIndeterminate ? kThemeMediumIndeterminateBar
|
|
|
|
|
: kThemeMediumProgressBar;
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
|
int32_t stepsPerSecond = mIsIndeterminate ? 60 : 30;
|
|
|
|
|
int32_t milliSecondsPerStep = 1000 / stepsPerSecond;
|
2013-03-08 00:03:39 -08:00
|
|
|
|
tdi.trackInfo.progress.phase = uint8_t(PR_IntervalToMilliseconds(PR_IntervalNow()) /
|
|
|
|
|
milliSecondsPerStep);
|
2011-04-21 02:07:32 -07:00
|
|
|
|
|
|
|
|
|
HIThemeDrawTrack(&tdi, NULL, cgContext, kHIThemeOrientationNormal);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
2011-09-08 06:30:32 -07:00
|
|
|
|
@interface ContextAwareSearchFieldCell : NSSearchFieldCell
|
|
|
|
|
{
|
|
|
|
|
nsIFrame* mContext;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// setContext: stores the searchfield nsIFrame so that it can be consulted
|
2012-07-30 07:20:58 -07:00
|
|
|
|
// during painting. Please reset this by calling setContext:nullptr as soon as
|
2011-09-08 06:30:32 -07:00
|
|
|
|
// you're done with painting because we don't want to keep a dangling pointer.
|
|
|
|
|
- (void)setContext:(nsIFrame*)aContext;
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
@implementation ContextAwareSearchFieldCell
|
|
|
|
|
|
|
|
|
|
- (id)initTextCell:(NSString*)aString
|
|
|
|
|
{
|
|
|
|
|
if ((self = [super initTextCell:aString])) {
|
2012-07-30 07:20:58 -07:00
|
|
|
|
mContext = nullptr;
|
2011-09-08 06:30:32 -07:00
|
|
|
|
}
|
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)setContext:(nsIFrame*)aContext
|
|
|
|
|
{
|
|
|
|
|
mContext = aContext;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static BOOL IsToolbarStyleContainer(nsIFrame* aFrame)
|
|
|
|
|
{
|
|
|
|
|
nsIContent* content = aFrame->GetContent();
|
|
|
|
|
if (!content)
|
|
|
|
|
return NO;
|
|
|
|
|
|
2011-10-14 11:11:22 -07:00
|
|
|
|
if (content->Tag() == nsGkAtoms::toolbar ||
|
|
|
|
|
content->Tag() == nsGkAtoms::toolbox ||
|
|
|
|
|
content->Tag() == nsGkAtoms::statusbar)
|
2011-09-08 06:30:32 -07:00
|
|
|
|
return YES;
|
|
|
|
|
|
2013-02-16 13:51:02 -08:00
|
|
|
|
switch (aFrame->StyleDisplay()->mAppearance) {
|
2011-09-08 06:30:32 -07:00
|
|
|
|
case NS_THEME_TOOLBAR:
|
|
|
|
|
case NS_THEME_MOZ_MAC_UNIFIED_TOOLBAR:
|
|
|
|
|
case NS_THEME_STATUSBAR:
|
|
|
|
|
return YES;
|
|
|
|
|
default:
|
|
|
|
|
return NO;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (BOOL)_isToolbarMode
|
|
|
|
|
{
|
|
|
|
|
// On 10.7, searchfields have two different styles, depending on whether
|
|
|
|
|
// the searchfield is on top of of window chrome. This function is called on
|
|
|
|
|
// 10.7 during drawing in order to determine which style to use.
|
|
|
|
|
for (nsIFrame* frame = mContext; frame; frame = frame->GetParent()) {
|
|
|
|
|
if (IsToolbarStyleContainer(frame)) {
|
|
|
|
|
return YES;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return NO;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
2010-10-13 08:56:16 -07:00
|
|
|
|
// Workaround for Bug 542048
|
|
|
|
|
// On 64-bit, NSSearchFieldCells don't draw focus rings.
|
|
|
|
|
#if defined(__x86_64__)
|
|
|
|
|
|
2011-09-08 06:30:32 -07:00
|
|
|
|
@interface SearchFieldCellWithFocusRing : ContextAwareSearchFieldCell {} @end
|
2010-10-13 08:56:16 -07:00
|
|
|
|
|
|
|
|
|
@implementation SearchFieldCellWithFocusRing
|
|
|
|
|
|
|
|
|
|
- (void)drawWithFrame:(NSRect)rect inView:(NSView*)controlView
|
|
|
|
|
{
|
|
|
|
|
[super drawWithFrame:rect inView:controlView];
|
2014-08-20 08:09:44 -07:00
|
|
|
|
|
2014-09-18 02:17:05 -07:00
|
|
|
|
if (FocusIsDrawnByDrawWithFrame()) {
|
|
|
|
|
DrawFocusRingForCellIfNeeded(self, rect, controlView);
|
|
|
|
|
}
|
2014-08-20 08:09:44 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)drawFocusRingMaskWithFrame:(NSRect)rect inView:(NSView*)controlView
|
|
|
|
|
{
|
|
|
|
|
// By default this draws nothing. I don't know why.
|
|
|
|
|
// We just draw the search field again. It's a great mask shape for its own
|
|
|
|
|
// focus ring.
|
|
|
|
|
[super drawWithFrame:rect inView:controlView];
|
2010-10-13 08:56:16 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
2014-07-03 01:06:56 -07:00
|
|
|
|
#endif
|
2007-04-10 17:25:11 -07:00
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
|
#define HITHEME_ORIENTATION kHIThemeOrientationNormal
|
2008-01-08 18:52:36 -08:00
|
|
|
|
#define MAX_FOCUS_RING_WIDTH 4
|
|
|
|
|
|
|
|
|
|
// These enums are for indexing into the margin array.
|
|
|
|
|
enum {
|
2011-03-18 07:10:01 -07:00
|
|
|
|
leopardOS = 0
|
2008-01-08 18:52:36 -08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
enum {
|
|
|
|
|
miniControlSize,
|
|
|
|
|
smallControlSize,
|
|
|
|
|
regularControlSize
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
enum {
|
|
|
|
|
leftMargin,
|
|
|
|
|
topMargin,
|
|
|
|
|
rightMargin,
|
|
|
|
|
bottomMargin
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static int EnumSizeForCocoaSize(NSControlSize cocoaControlSize) {
|
|
|
|
|
if (cocoaControlSize == NSMiniControlSize)
|
|
|
|
|
return miniControlSize;
|
|
|
|
|
else if (cocoaControlSize == NSSmallControlSize)
|
|
|
|
|
return smallControlSize;
|
|
|
|
|
else
|
|
|
|
|
return regularControlSize;
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
|
static NSControlSize CocoaSizeForEnum(int32_t enumControlSize) {
|
2011-07-08 05:56:44 -07:00
|
|
|
|
if (enumControlSize == miniControlSize)
|
|
|
|
|
return NSMiniControlSize;
|
|
|
|
|
else if (enumControlSize == smallControlSize)
|
|
|
|
|
return NSSmallControlSize;
|
|
|
|
|
else
|
|
|
|
|
return NSRegularControlSize;
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-08 07:42:45 -07:00
|
|
|
|
static NSString* CUIControlSizeForCocoaSize(NSControlSize aControlSize)
|
|
|
|
|
{
|
|
|
|
|
if (aControlSize == NSRegularControlSize)
|
|
|
|
|
return @"regular";
|
|
|
|
|
else if (aControlSize == NSSmallControlSize)
|
|
|
|
|
return @"small";
|
|
|
|
|
else
|
|
|
|
|
return @"mini";
|
|
|
|
|
}
|
|
|
|
|
|
2008-01-08 18:52:36 -08:00
|
|
|
|
static void InflateControlRect(NSRect* rect, NSControlSize cocoaControlSize, const float marginSet[][3][4])
|
|
|
|
|
{
|
2008-10-13 09:58:40 -07:00
|
|
|
|
if (!marginSet)
|
|
|
|
|
return;
|
2010-02-23 15:30:39 -08:00
|
|
|
|
|
|
|
|
|
static int osIndex = leopardOS;
|
2008-01-08 18:52:36 -08:00
|
|
|
|
int controlSize = EnumSizeForCocoaSize(cocoaControlSize);
|
|
|
|
|
const float* buttonMargins = marginSet[osIndex][controlSize];
|
|
|
|
|
rect->origin.x -= buttonMargins[leftMargin];
|
|
|
|
|
rect->origin.y -= buttonMargins[bottomMargin];
|
|
|
|
|
rect->size.width += buttonMargins[leftMargin] + buttonMargins[rightMargin];
|
|
|
|
|
rect->size.height += buttonMargins[bottomMargin] + buttonMargins[topMargin];
|
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
2009-08-03 15:25:20 -07:00
|
|
|
|
static NSWindow* NativeWindowForFrame(nsIFrame* aFrame,
|
2008-09-22 01:57:42 -07:00
|
|
|
|
nsIWidget** aTopLevelWidget = NULL)
|
2008-09-16 01:21:06 -07:00
|
|
|
|
{
|
|
|
|
|
if (!aFrame)
|
|
|
|
|
return nil;
|
|
|
|
|
|
2010-07-02 12:11:04 -07:00
|
|
|
|
nsIWidget* widget = aFrame->GetNearestWidget();
|
2008-09-16 01:21:06 -07:00
|
|
|
|
if (!widget)
|
|
|
|
|
return nil;
|
|
|
|
|
|
2009-08-03 15:25:20 -07:00
|
|
|
|
nsIWidget* topLevelWidget = widget->GetTopLevelWidget();
|
2008-09-22 01:57:42 -07:00
|
|
|
|
if (aTopLevelWidget)
|
|
|
|
|
*aTopLevelWidget = topLevelWidget;
|
2008-09-16 01:21:06 -07:00
|
|
|
|
|
|
|
|
|
return (NSWindow*)topLevelWidget->GetNativeData(NS_NATIVE_WINDOW);
|
|
|
|
|
}
|
2007-05-08 05:54:48 -07:00
|
|
|
|
|
2013-06-12 14:42:00 -07:00
|
|
|
|
static NSSize
|
|
|
|
|
WindowButtonsSize(nsIFrame* aFrame)
|
2013-05-02 11:15:29 -07:00
|
|
|
|
{
|
|
|
|
|
NSWindow* window = NativeWindowForFrame(aFrame);
|
2013-05-03 10:31:01 -07:00
|
|
|
|
if (!window) {
|
2013-06-07 02:55:30 -07:00
|
|
|
|
// Return fallback values.
|
|
|
|
|
if (!nsCocoaFeatures::OnLionOrLater())
|
2013-06-12 14:42:00 -07:00
|
|
|
|
return NSMakeSize(57, 16);
|
|
|
|
|
return NSMakeSize(54, 16);
|
2013-05-02 11:15:29 -07:00
|
|
|
|
}
|
|
|
|
|
|
2013-05-03 10:31:01 -07:00
|
|
|
|
NSRect buttonBox = NSZeroRect;
|
|
|
|
|
NSButton* closeButton = [window standardWindowButton:NSWindowCloseButton];
|
|
|
|
|
if (closeButton) {
|
|
|
|
|
buttonBox = NSUnionRect(buttonBox, [closeButton frame]);
|
|
|
|
|
}
|
|
|
|
|
NSButton* minimizeButton = [window standardWindowButton:NSWindowMiniaturizeButton];
|
|
|
|
|
if (minimizeButton) {
|
|
|
|
|
buttonBox = NSUnionRect(buttonBox, [minimizeButton frame]);
|
|
|
|
|
}
|
|
|
|
|
NSButton* zoomButton = [window standardWindowButton:NSWindowZoomButton];
|
|
|
|
|
if (zoomButton) {
|
|
|
|
|
buttonBox = NSUnionRect(buttonBox, [zoomButton frame]);
|
2013-05-02 11:15:29 -07:00
|
|
|
|
}
|
2013-06-12 14:42:00 -07:00
|
|
|
|
return buttonBox.size;
|
2013-05-02 11:15:29 -07:00
|
|
|
|
}
|
|
|
|
|
|
2008-09-22 01:57:42 -07:00
|
|
|
|
static BOOL FrameIsInActiveWindow(nsIFrame* aFrame)
|
|
|
|
|
{
|
|
|
|
|
nsIWidget* topLevelWidget = NULL;
|
2009-08-03 15:25:20 -07:00
|
|
|
|
NSWindow* win = NativeWindowForFrame(aFrame, &topLevelWidget);
|
2008-09-22 01:57:42 -07:00
|
|
|
|
if (!topLevelWidget || !win)
|
|
|
|
|
return YES;
|
|
|
|
|
|
|
|
|
|
// XUL popups, e.g. the toolbar customization popup, can't become key windows,
|
|
|
|
|
// but controls in these windows should still get the active look.
|
2014-03-19 09:48:08 -07:00
|
|
|
|
if (topLevelWidget->WindowType() == eWindowType_popup)
|
2008-11-27 14:38:24 -08:00
|
|
|
|
return YES;
|
|
|
|
|
if ([win isSheet])
|
|
|
|
|
return [win isKeyWindow];
|
|
|
|
|
return [win isMainWindow] && ![win attachedSheet];
|
2008-09-22 01:57:42 -07:00
|
|
|
|
}
|
|
|
|
|
|
2011-08-08 07:42:45 -07:00
|
|
|
|
// Toolbar controls and content controls respond to different window
|
|
|
|
|
// activeness states.
|
|
|
|
|
static BOOL IsActive(nsIFrame* aFrame, BOOL aIsToolbarControl)
|
|
|
|
|
{
|
|
|
|
|
if (aIsToolbarControl)
|
2012-08-20 03:00:49 -07:00
|
|
|
|
return [NativeWindowForFrame(aFrame) isMainWindow];
|
2011-08-08 07:42:45 -07:00
|
|
|
|
return FrameIsInActiveWindow(aFrame);
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-27 00:06:00 -07:00
|
|
|
|
NS_IMPL_ISUPPORTS_INHERITED(nsNativeThemeCocoa, nsNativeTheme, nsITheme)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
nsNativeThemeCocoa::nsNativeThemeCocoa()
|
|
|
|
|
{
|
2008-02-20 17:01:27 -08:00
|
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
|
2011-04-08 23:56:56 -07:00
|
|
|
|
// provide a local autorelease pool, as this is called during startup
|
|
|
|
|
// before the main event-loop pool is in place
|
|
|
|
|
nsAutoreleasePool pool;
|
|
|
|
|
|
2014-02-27 09:12:16 -08:00
|
|
|
|
mHelpButtonCell = [[NSButtonCell alloc] initTextCell:nil];
|
|
|
|
|
[mHelpButtonCell setBezelStyle:NSHelpButtonBezelStyle];
|
|
|
|
|
[mHelpButtonCell setButtonType:NSMomentaryPushInButton];
|
|
|
|
|
[mHelpButtonCell setHighlightsBy:NSPushInCellMask];
|
|
|
|
|
|
2007-12-23 11:22:47 -08:00
|
|
|
|
mPushButtonCell = [[NSButtonCell alloc] initTextCell:nil];
|
|
|
|
|
[mPushButtonCell setButtonType:NSMomentaryPushInButton];
|
|
|
|
|
[mPushButtonCell setHighlightsBy:NSPushInCellMask];
|
2008-01-13 20:48:33 -08:00
|
|
|
|
|
|
|
|
|
mRadioButtonCell = [[NSButtonCell alloc] initTextCell:nil];
|
|
|
|
|
[mRadioButtonCell setButtonType:NSRadioButton];
|
2008-10-13 09:58:40 -07:00
|
|
|
|
|
|
|
|
|
mCheckboxCell = [[NSButtonCell alloc] initTextCell:nil];
|
|
|
|
|
[mCheckboxCell setButtonType:NSSwitchButton];
|
2009-01-29 23:19:41 -08:00
|
|
|
|
[mCheckboxCell setAllowsMixedState:YES];
|
2008-02-20 17:01:27 -08:00
|
|
|
|
|
2010-10-13 08:56:16 -07:00
|
|
|
|
#if defined(__x86_64__)
|
|
|
|
|
mSearchFieldCell = [[SearchFieldCellWithFocusRing alloc] initTextCell:@""];
|
|
|
|
|
#else
|
2011-09-08 06:30:32 -07:00
|
|
|
|
mSearchFieldCell = [[ContextAwareSearchFieldCell alloc] initTextCell:@""];
|
2010-10-13 08:56:16 -07:00
|
|
|
|
#endif
|
2008-12-06 03:40:58 -08:00
|
|
|
|
[mSearchFieldCell setBezelStyle:NSTextFieldRoundedBezel];
|
|
|
|
|
[mSearchFieldCell setBezeled:YES];
|
|
|
|
|
[mSearchFieldCell setEditable:YES];
|
|
|
|
|
[mSearchFieldCell setFocusRingType:NSFocusRingTypeExterior];
|
|
|
|
|
|
2009-01-31 08:49:29 -08:00
|
|
|
|
mDropdownCell = [[NSPopUpButtonCell alloc] initTextCell:@"" pullsDown:NO];
|
|
|
|
|
|
2010-02-23 15:30:39 -08:00
|
|
|
|
mComboBoxCell = [[NSComboBoxCell alloc] initTextCell:@""];
|
2009-02-11 07:54:10 -08:00
|
|
|
|
[mComboBoxCell setBezeled:YES];
|
|
|
|
|
[mComboBoxCell setEditable:YES];
|
|
|
|
|
[mComboBoxCell setFocusRingType:NSFocusRingTypeExterior];
|
|
|
|
|
|
2011-04-21 02:07:32 -07:00
|
|
|
|
mProgressBarCell = [[NSProgressBarCell alloc] init];
|
|
|
|
|
|
2012-06-06 00:56:28 -07:00
|
|
|
|
mMeterBarCell = [[NSLevelIndicatorCell alloc]
|
|
|
|
|
initWithLevelIndicatorStyle:NSContinuousCapacityLevelIndicatorStyle];
|
|
|
|
|
|
2009-09-16 15:06:16 -07:00
|
|
|
|
mCellDrawView = [[CellDrawView alloc] init];
|
|
|
|
|
|
2008-02-20 17:01:27 -08:00
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nsNativeThemeCocoa::~nsNativeThemeCocoa()
|
|
|
|
|
{
|
2008-02-20 17:01:27 -08:00
|
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
|
2012-06-06 00:56:28 -07:00
|
|
|
|
[mMeterBarCell release];
|
2011-04-21 02:07:32 -07:00
|
|
|
|
[mProgressBarCell release];
|
2014-02-27 09:12:16 -08:00
|
|
|
|
[mHelpButtonCell release];
|
2007-12-23 11:22:47 -08:00
|
|
|
|
[mPushButtonCell release];
|
2008-01-13 20:48:33 -08:00
|
|
|
|
[mRadioButtonCell release];
|
2008-10-13 09:58:40 -07:00
|
|
|
|
[mCheckboxCell release];
|
2008-12-06 03:40:58 -08:00
|
|
|
|
[mSearchFieldCell release];
|
2009-01-31 08:49:29 -08:00
|
|
|
|
[mDropdownCell release];
|
2009-02-11 07:54:10 -08:00
|
|
|
|
[mComboBoxCell release];
|
2009-09-16 15:06:16 -07:00
|
|
|
|
[mCellDrawView release];
|
2008-02-20 17:01:27 -08:00
|
|
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
}
|
|
|
|
|
|
2008-12-03 08:38:59 -08:00
|
|
|
|
// Limit on the area of the target rect (in pixels^2) in
|
|
|
|
|
// DrawCellWithScaling(), DrawButton() and DrawScrollbar(), above which we
|
|
|
|
|
// don't draw the object into a bitmap buffer. This is to avoid crashes in
|
2008-09-17 08:17:08 -07:00
|
|
|
|
// [NSGraphicsContext graphicsContextWithGraphicsPort:flipped:] and
|
|
|
|
|
// CGContextDrawImage(), and also to avoid very poor drawing performance in
|
2008-12-03 08:38:59 -08:00
|
|
|
|
// CGContextDrawImage() when it scales the bitmap (particularly if xscale or
|
|
|
|
|
// yscale is less than but near 1 -- e.g. 0.9). This value was determined
|
|
|
|
|
// by trial and error, on OS X 10.4.11 and 10.5.4, and on systems with
|
|
|
|
|
// different amounts of RAM.
|
|
|
|
|
#define BITMAP_MAX_AREA 500000
|
2008-09-17 08:17:08 -07:00
|
|
|
|
|
2012-08-13 09:45:57 -07:00
|
|
|
|
static int
|
|
|
|
|
GetBackingScaleFactorForRendering(CGContextRef cgContext)
|
|
|
|
|
{
|
|
|
|
|
CGAffineTransform ctm = CGContextGetUserSpaceToDeviceSpaceTransform(cgContext);
|
|
|
|
|
CGRect transformedUserSpacePixel = CGRectApplyAffineTransform(CGRectMake(0, 0, 1, 1), ctm);
|
2013-01-15 04:22:03 -08:00
|
|
|
|
float maxScale = std::max(fabs(transformedUserSpacePixel.size.width),
|
2012-08-13 09:45:57 -07:00
|
|
|
|
fabs(transformedUserSpacePixel.size.height));
|
|
|
|
|
return maxScale > 1.0 ? 2 : 1;
|
|
|
|
|
}
|
|
|
|
|
|
2008-03-04 12:51:54 -08:00
|
|
|
|
/*
|
|
|
|
|
* Draw the given NSCell into the given cgContext.
|
|
|
|
|
*
|
|
|
|
|
* destRect - the size and position of the resulting control rectangle
|
|
|
|
|
* controlSize - the NSControlSize which will be given to the NSCell before
|
|
|
|
|
* asking it to render
|
2008-10-13 09:58:40 -07:00
|
|
|
|
* naturalSize - The natural dimensions of this control.
|
2008-03-04 12:51:54 -08:00
|
|
|
|
* If the control rect size is not equal to either of these, a scale
|
|
|
|
|
* will be applied to the context so that rendering the control at the
|
|
|
|
|
* natural size will result in it filling the destRect space.
|
|
|
|
|
* If a control has no natural dimensions in either/both axes, pass 0.0f.
|
2008-10-13 09:58:40 -07:00
|
|
|
|
* minimumSize - The minimum dimensions of this control.
|
2008-03-04 12:51:54 -08:00
|
|
|
|
* If the control rect size is less than the minimum for a given axis,
|
|
|
|
|
* a scale will be applied to the context so that the minimum is used
|
|
|
|
|
* for drawing. If a control has no minimum dimensions in either/both
|
|
|
|
|
* axes, pass 0.0f.
|
|
|
|
|
* marginSet - an array of margins; a multidimensional array of [2][3][4],
|
2008-10-13 09:58:40 -07:00
|
|
|
|
* with the first dimension being the OS version (Tiger or Leopard),
|
|
|
|
|
* the second being the control size (mini, small, regular), and the third
|
|
|
|
|
* being the 4 margin values (left, top, right, bottom).
|
2008-12-06 03:40:58 -08:00
|
|
|
|
* view - The NSView that we're drawing into. As far as I can tell, it doesn't
|
|
|
|
|
* matter if this is really the right view; it just has to return YES when
|
|
|
|
|
* asked for isFlipped. Otherwise we'll get drawing bugs on 10.4.
|
2009-04-17 01:12:12 -07:00
|
|
|
|
* mirrorHorizontal - whether to mirror the cell horizontally
|
2008-03-04 12:51:54 -08:00
|
|
|
|
*/
|
2008-10-13 09:58:40 -07:00
|
|
|
|
static void DrawCellWithScaling(NSCell *cell,
|
|
|
|
|
CGContextRef cgContext,
|
|
|
|
|
const HIRect& destRect,
|
|
|
|
|
NSControlSize controlSize,
|
|
|
|
|
NSSize naturalSize,
|
|
|
|
|
NSSize minimumSize,
|
|
|
|
|
const float marginSet[][3][4],
|
2009-04-17 01:12:12 -07:00
|
|
|
|
NSView* view,
|
|
|
|
|
BOOL mirrorHorizontal)
|
2008-01-13 20:48:33 -08:00
|
|
|
|
{
|
2008-02-20 17:01:27 -08:00
|
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
|
2008-03-04 13:07:04 -08:00
|
|
|
|
NSRect drawRect = NSMakeRect(destRect.origin.x, destRect.origin.y, destRect.size.width, destRect.size.height);
|
2008-01-13 20:48:33 -08:00
|
|
|
|
|
2008-10-13 09:58:40 -07:00
|
|
|
|
if (naturalSize.width != 0.0f)
|
|
|
|
|
drawRect.size.width = naturalSize.width;
|
|
|
|
|
if (naturalSize.height != 0.0f)
|
|
|
|
|
drawRect.size.height = naturalSize.height;
|
2008-01-13 20:48:33 -08:00
|
|
|
|
|
2008-10-13 09:58:40 -07:00
|
|
|
|
// Keep aspect ratio when scaling if one dimension is free.
|
|
|
|
|
if (naturalSize.width == 0.0f && naturalSize.height != 0.0f)
|
|
|
|
|
drawRect.size.width = destRect.size.width * naturalSize.height / destRect.size.height;
|
|
|
|
|
if (naturalSize.height == 0.0f && naturalSize.width != 0.0f)
|
|
|
|
|
drawRect.size.height = destRect.size.height * naturalSize.width / destRect.size.width;
|
2008-01-13 20:48:33 -08:00
|
|
|
|
|
2008-10-13 09:58:40 -07:00
|
|
|
|
// Honor minimum sizes.
|
|
|
|
|
if (drawRect.size.width < minimumSize.width)
|
|
|
|
|
drawRect.size.width = minimumSize.width;
|
|
|
|
|
if (drawRect.size.height < minimumSize.height)
|
|
|
|
|
drawRect.size.height = minimumSize.height;
|
2008-01-13 20:48:33 -08:00
|
|
|
|
|
2008-11-09 14:30:46 -08:00
|
|
|
|
[NSGraphicsContext saveGraphicsState];
|
2008-01-13 20:48:33 -08:00
|
|
|
|
|
2008-12-06 03:40:58 -08:00
|
|
|
|
// Only skip the buffer if the area of our cell (in pixels^2) is too large.
|
|
|
|
|
if (drawRect.size.width * drawRect.size.height > BITMAP_MAX_AREA) {
|
2008-03-14 12:29:32 -07:00
|
|
|
|
// Inflate the rect Gecko gave us by the margin for the control.
|
|
|
|
|
InflateControlRect(&drawRect, controlSize, marginSet);
|
2008-01-13 20:48:33 -08:00
|
|
|
|
|
2008-11-09 14:30:46 -08:00
|
|
|
|
NSGraphicsContext* savedContext = [NSGraphicsContext currentContext];
|
2008-03-14 12:29:32 -07:00
|
|
|
|
[NSGraphicsContext setCurrentContext:[NSGraphicsContext graphicsContextWithGraphicsPort:cgContext flipped:YES]];
|
|
|
|
|
|
2014-02-13 03:09:59 -08:00
|
|
|
|
DrawCellIncludingFocusRing(cell, drawRect, view);
|
2008-11-09 14:30:46 -08:00
|
|
|
|
|
|
|
|
|
[NSGraphicsContext setCurrentContext:savedContext];
|
2008-03-14 12:29:32 -07:00
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
float w = ceil(drawRect.size.width);
|
|
|
|
|
float h = ceil(drawRect.size.height);
|
2008-12-06 03:40:58 -08:00
|
|
|
|
NSRect tmpRect = NSMakeRect(MAX_FOCUS_RING_WIDTH, MAX_FOCUS_RING_WIDTH, w, h);
|
2008-03-14 12:29:32 -07:00
|
|
|
|
|
|
|
|
|
// inflate to figure out the frame we need to tell NSCell to draw in, to get something that's 0,0,w,h
|
|
|
|
|
InflateControlRect(&tmpRect, controlSize, marginSet);
|
|
|
|
|
|
|
|
|
|
// and then, expand by MAX_FOCUS_RING_WIDTH size to make sure we can capture any focus ring
|
|
|
|
|
w += MAX_FOCUS_RING_WIDTH * 2.0;
|
|
|
|
|
h += MAX_FOCUS_RING_WIDTH * 2.0;
|
|
|
|
|
|
2012-08-13 09:45:57 -07:00
|
|
|
|
int backingScaleFactor = GetBackingScaleFactorForRendering(cgContext);
|
2008-03-14 12:29:32 -07:00
|
|
|
|
CGColorSpaceRef rgb = CGColorSpaceCreateDeviceRGB();
|
|
|
|
|
CGContextRef ctx = CGBitmapContextCreate(NULL,
|
2012-08-13 09:45:57 -07:00
|
|
|
|
(int) w * backingScaleFactor, (int) h * backingScaleFactor,
|
|
|
|
|
8, (int) w * backingScaleFactor * 4,
|
2008-03-14 12:29:32 -07:00
|
|
|
|
rgb, kCGImageAlphaPremultipliedFirst);
|
|
|
|
|
CGColorSpaceRelease(rgb);
|
|
|
|
|
|
2008-12-06 03:40:58 -08:00
|
|
|
|
// We need to flip the image twice in order to avoid drawing bugs on 10.4, see bug 465069.
|
|
|
|
|
// This is the first flip transform, applied to cgContext.
|
|
|
|
|
CGContextScaleCTM(cgContext, 1.0f, -1.0f);
|
|
|
|
|
CGContextTranslateCTM(cgContext, 0.0f, -(2.0 * destRect.origin.y + destRect.size.height));
|
2009-04-17 01:12:12 -07:00
|
|
|
|
if (mirrorHorizontal) {
|
|
|
|
|
CGContextScaleCTM(cgContext, -1.0f, 1.0f);
|
|
|
|
|
CGContextTranslateCTM(cgContext, -(2.0 * destRect.origin.x + destRect.size.width), 0.0f);
|
|
|
|
|
}
|
2008-03-14 12:29:32 -07:00
|
|
|
|
|
2008-11-09 14:30:46 -08:00
|
|
|
|
NSGraphicsContext* savedContext = [NSGraphicsContext currentContext];
|
2008-03-14 12:29:32 -07:00
|
|
|
|
[NSGraphicsContext setCurrentContext:[NSGraphicsContext graphicsContextWithGraphicsPort:ctx flipped:YES]];
|
|
|
|
|
|
2012-08-13 09:45:57 -07:00
|
|
|
|
CGContextScaleCTM(ctx, backingScaleFactor, backingScaleFactor);
|
|
|
|
|
|
2014-09-18 01:52:35 -07:00
|
|
|
|
// Set the context's "base transform" to in order to get correctly-sized focus rings.
|
|
|
|
|
CGContextSetBaseCTM(ctx, CGAffineTransformMakeScale(backingScaleFactor, backingScaleFactor));
|
|
|
|
|
|
2008-12-06 03:40:58 -08:00
|
|
|
|
// This is the second flip transform, applied to ctx.
|
|
|
|
|
CGContextScaleCTM(ctx, 1.0f, -1.0f);
|
|
|
|
|
CGContextTranslateCTM(ctx, 0.0f, -(2.0 * tmpRect.origin.y + tmpRect.size.height));
|
|
|
|
|
|
2014-02-13 03:09:59 -08:00
|
|
|
|
DrawCellIncludingFocusRing(cell, tmpRect, view);
|
2008-03-14 12:29:32 -07:00
|
|
|
|
|
|
|
|
|
[NSGraphicsContext setCurrentContext:savedContext];
|
|
|
|
|
|
|
|
|
|
CGImageRef img = CGBitmapContextCreateImage(ctx);
|
|
|
|
|
|
|
|
|
|
// Drop the image into the original destination rectangle, scaling to fit
|
2008-10-13 09:58:40 -07:00
|
|
|
|
// Only scale MAX_FOCUS_RING_WIDTH by xscale/yscale when the resulting rect
|
|
|
|
|
// doesn't extend beyond the overflow rect
|
|
|
|
|
float xscale = destRect.size.width / drawRect.size.width;
|
|
|
|
|
float yscale = destRect.size.height / drawRect.size.height;
|
|
|
|
|
float scaledFocusRingX = xscale < 1.0f ? MAX_FOCUS_RING_WIDTH * xscale : MAX_FOCUS_RING_WIDTH;
|
|
|
|
|
float scaledFocusRingY = yscale < 1.0f ? MAX_FOCUS_RING_WIDTH * yscale : MAX_FOCUS_RING_WIDTH;
|
|
|
|
|
CGContextDrawImage(cgContext, CGRectMake(destRect.origin.x - scaledFocusRingX,
|
|
|
|
|
destRect.origin.y - scaledFocusRingY,
|
|
|
|
|
destRect.size.width + scaledFocusRingX * 2,
|
|
|
|
|
destRect.size.height + scaledFocusRingY * 2),
|
2008-03-14 12:29:32 -07:00
|
|
|
|
img);
|
|
|
|
|
|
|
|
|
|
CGImageRelease(img);
|
|
|
|
|
CGContextRelease(ctx);
|
|
|
|
|
}
|
2008-01-13 20:48:33 -08:00
|
|
|
|
|
2008-11-09 14:30:46 -08:00
|
|
|
|
[NSGraphicsContext restoreGraphicsState];
|
2008-03-14 12:29:32 -07:00
|
|
|
|
|
2008-01-13 20:48:33 -08:00
|
|
|
|
#if DRAW_IN_FRAME_DEBUG
|
2008-03-14 12:29:32 -07:00
|
|
|
|
CGContextSetRGBFillColor(cgContext, 0.0, 0.0, 0.5, 0.25);
|
2008-03-04 12:51:54 -08:00
|
|
|
|
CGContextFillRect(cgContext, destRect);
|
2008-01-13 20:48:33 -08:00
|
|
|
|
#endif
|
2008-02-20 17:01:27 -08:00
|
|
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
2008-01-13 20:48:33 -08:00
|
|
|
|
}
|
2008-09-22 01:57:42 -07:00
|
|
|
|
|
2008-10-13 09:58:40 -07:00
|
|
|
|
struct CellRenderSettings {
|
|
|
|
|
// The natural dimensions of the control.
|
|
|
|
|
// If a control has no natural dimensions in either/both axes, set to 0.0f.
|
|
|
|
|
NSSize naturalSizes[3];
|
|
|
|
|
|
|
|
|
|
// The minimum dimensions of the control.
|
|
|
|
|
// If a control has no minimum dimensions in either/both axes, set to 0.0f.
|
|
|
|
|
NSSize minimumSizes[3];
|
|
|
|
|
|
2011-03-30 05:41:08 -07:00
|
|
|
|
// A three-dimensional array,
|
2011-03-18 07:10:01 -07:00
|
|
|
|
// with the first dimension being the OS version (only Leopard for the moment),
|
2008-10-13 09:58:40 -07:00
|
|
|
|
// the second being the control size (mini, small, regular), and the third
|
|
|
|
|
// being the 4 margin values (left, top, right, bottom).
|
2011-03-18 07:10:01 -07:00
|
|
|
|
float margins[1][3][4];
|
2008-10-13 09:58:40 -07:00
|
|
|
|
};
|
|
|
|
|
|
2011-07-08 05:56:44 -07:00
|
|
|
|
/*
|
|
|
|
|
* This is a helper method that returns the required NSControlSize given a size
|
|
|
|
|
* and the size of the three controls plus a tolerance.
|
|
|
|
|
* size - The width or the height of the element to draw.
|
|
|
|
|
* sizes - An array with the all the width/height of the element for its
|
|
|
|
|
* different sizes.
|
|
|
|
|
* tolerance - The tolerance as passed to DrawCellWithSnapping.
|
|
|
|
|
* NOTE: returns NSRegularControlSize if all values in 'sizes' are zero.
|
|
|
|
|
*/
|
2011-08-08 07:42:45 -07:00
|
|
|
|
static NSControlSize FindControlSize(CGFloat size, const CGFloat* sizes, CGFloat tolerance)
|
2011-07-08 05:56:44 -07:00
|
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
|
for (uint32_t i = miniControlSize; i <= regularControlSize; ++i) {
|
2011-07-08 05:56:44 -07:00
|
|
|
|
if (sizes[i] == 0) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CGFloat next = 0;
|
|
|
|
|
// Find next value.
|
2012-08-22 08:56:38 -07:00
|
|
|
|
for (uint32_t j = i+1; j <= regularControlSize; ++j) {
|
2011-07-08 05:56:44 -07:00
|
|
|
|
if (sizes[j] != 0) {
|
|
|
|
|
next = sizes[j];
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If it's the latest value, we pick it.
|
|
|
|
|
if (next == 0) {
|
|
|
|
|
return CocoaSizeForEnum(i);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (size <= sizes[i] + tolerance && size < next) {
|
|
|
|
|
return CocoaSizeForEnum(i);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If we are here, that means sizes[] was an array with only empty values
|
|
|
|
|
// or the algorithm above is wrong.
|
|
|
|
|
// The former can happen but the later would be wrong.
|
|
|
|
|
NS_ASSERTION(sizes[0] == 0 && sizes[1] == 0 && sizes[2] == 0,
|
|
|
|
|
"We found no control! We shouldn't be there!");
|
|
|
|
|
return CocoaSizeForEnum(regularControlSize);
|
|
|
|
|
}
|
|
|
|
|
|
2008-10-13 09:58:40 -07:00
|
|
|
|
/*
|
|
|
|
|
* Draw the given NSCell into the given cgContext with a nice control size.
|
|
|
|
|
*
|
|
|
|
|
* This function is similar to DrawCellWithScaling, but it decides what
|
|
|
|
|
* control size to use based on the destRect's size.
|
|
|
|
|
* Scaling is only applied when the difference between the destRect's size
|
2009-01-12 11:22:59 -08:00
|
|
|
|
* and the next smaller natural size is greater than snapTolerance. Otherwise
|
2008-10-13 09:58:40 -07:00
|
|
|
|
* it snaps to the next smaller control size without scaling because unscaled
|
|
|
|
|
* controls look nicer.
|
|
|
|
|
*/
|
|
|
|
|
static void DrawCellWithSnapping(NSCell *cell,
|
|
|
|
|
CGContextRef cgContext,
|
|
|
|
|
const HIRect& destRect,
|
|
|
|
|
const CellRenderSettings settings,
|
|
|
|
|
float verticalAlignFactor,
|
2009-01-12 11:22:59 -08:00
|
|
|
|
NSView* view,
|
2009-04-17 01:12:12 -07:00
|
|
|
|
BOOL mirrorHorizontal,
|
2009-01-12 11:22:59 -08:00
|
|
|
|
float snapTolerance = 2.0f)
|
2008-10-13 09:58:40 -07:00
|
|
|
|
{
|
|
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
|
|
|
|
|
const float rectWidth = destRect.size.width, rectHeight = destRect.size.height;
|
|
|
|
|
const NSSize *sizes = settings.naturalSizes;
|
|
|
|
|
const NSSize miniSize = sizes[EnumSizeForCocoaSize(NSMiniControlSize)];
|
|
|
|
|
const NSSize smallSize = sizes[EnumSizeForCocoaSize(NSSmallControlSize)];
|
|
|
|
|
const NSSize regularSize = sizes[EnumSizeForCocoaSize(NSRegularControlSize)];
|
|
|
|
|
|
|
|
|
|
HIRect drawRect = destRect;
|
|
|
|
|
|
2011-07-08 05:56:44 -07:00
|
|
|
|
CGFloat controlWidths[3] = { miniSize.width, smallSize.width, regularSize.width };
|
|
|
|
|
NSControlSize controlSizeX = FindControlSize(rectWidth, controlWidths, snapTolerance);
|
|
|
|
|
CGFloat controlHeights[3] = { miniSize.height, smallSize.height, regularSize.height };
|
|
|
|
|
NSControlSize controlSizeY = FindControlSize(rectHeight, controlHeights, snapTolerance);
|
2008-10-13 09:58:40 -07:00
|
|
|
|
|
|
|
|
|
NSControlSize controlSize = NSRegularControlSize;
|
|
|
|
|
int sizeIndex = 0;
|
|
|
|
|
|
|
|
|
|
// At some sizes, don't scale but snap.
|
|
|
|
|
const NSControlSize smallerControlSize =
|
|
|
|
|
EnumSizeForCocoaSize(controlSizeX) < EnumSizeForCocoaSize(controlSizeY) ?
|
|
|
|
|
controlSizeX : controlSizeY;
|
|
|
|
|
const int smallerControlSizeIndex = EnumSizeForCocoaSize(smallerControlSize);
|
2008-12-06 03:40:58 -08:00
|
|
|
|
const NSSize size = sizes[smallerControlSizeIndex];
|
|
|
|
|
float diffWidth = size.width ? rectWidth - size.width : 0.0f;
|
|
|
|
|
float diffHeight = size.height ? rectHeight - size.height : 0.0f;
|
2008-10-13 09:58:40 -07:00
|
|
|
|
if (diffWidth >= 0.0f && diffHeight >= 0.0f &&
|
2009-01-12 11:22:59 -08:00
|
|
|
|
diffWidth <= snapTolerance && diffHeight <= snapTolerance) {
|
2008-10-13 09:58:40 -07:00
|
|
|
|
// Snap to the smaller control size.
|
|
|
|
|
controlSize = smallerControlSize;
|
|
|
|
|
sizeIndex = smallerControlSizeIndex;
|
|
|
|
|
// Resize and center the drawRect.
|
|
|
|
|
if (sizes[sizeIndex].width) {
|
|
|
|
|
drawRect.origin.x += ceil((destRect.size.width - sizes[sizeIndex].width) / 2);
|
|
|
|
|
drawRect.size.width = sizes[sizeIndex].width;
|
|
|
|
|
}
|
|
|
|
|
if (sizes[sizeIndex].height) {
|
|
|
|
|
drawRect.origin.y += floor((destRect.size.height - sizes[sizeIndex].height) * verticalAlignFactor);
|
|
|
|
|
drawRect.size.height = sizes[sizeIndex].height;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// Use the larger control size.
|
|
|
|
|
controlSize = EnumSizeForCocoaSize(controlSizeX) > EnumSizeForCocoaSize(controlSizeY) ?
|
|
|
|
|
controlSizeX : controlSizeY;
|
|
|
|
|
sizeIndex = EnumSizeForCocoaSize(controlSize);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[cell setControlSize:controlSize];
|
|
|
|
|
|
|
|
|
|
NSSize minimumSize = settings.minimumSizes ? settings.minimumSizes[sizeIndex] : NSZeroSize;
|
|
|
|
|
DrawCellWithScaling(cell, cgContext, drawRect, controlSize, sizes[sizeIndex],
|
2009-04-17 01:12:12 -07:00
|
|
|
|
minimumSize, settings.margins, view, mirrorHorizontal);
|
2008-10-13 09:58:40 -07:00
|
|
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-27 17:15:27 -07:00
|
|
|
|
@interface NSWindow(CoreUIRendererPrivate)
|
|
|
|
|
+ (CUIRendererRef)coreUIRenderer;
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
RenderWithCoreUILegacy(CGRect aRect, CGContextRef cgContext, NSDictionary* aOptions)
|
|
|
|
|
{
|
|
|
|
|
if (aRect.size.width * aRect.size.height <= BITMAP_MAX_AREA) {
|
|
|
|
|
CUIRendererRef renderer = [NSWindow respondsToSelector:@selector(coreUIRenderer)]
|
|
|
|
|
? [NSWindow coreUIRenderer] : nil;
|
|
|
|
|
CUIDraw(renderer, aRect, cgContext, (CFDictionaryRef)aOptions, NULL);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static id
|
|
|
|
|
GetAquaAppearance()
|
|
|
|
|
{
|
|
|
|
|
// We only need NSAppearance on 10.10 and up.
|
|
|
|
|
if (nsCocoaFeatures::OnYosemiteOrLater()) {
|
|
|
|
|
Class NSAppearanceClass = NSClassFromString(@"NSAppearance");
|
|
|
|
|
if (NSAppearanceClass &&
|
|
|
|
|
[NSAppearanceClass respondsToSelector:@selector(appearanceNamed:)]) {
|
|
|
|
|
return [NSAppearanceClass performSelector:@selector(appearanceNamed:)
|
|
|
|
|
withObject:@"NSAppearanceNameAqua"];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return nil;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@interface NSObject(NSAppearanceCoreUIRendering)
|
|
|
|
|
- (void)_drawInRect:(CGRect)rect context:(CGContextRef)cgContext options:(id)options;
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
RenderWithCoreUI(CGRect aRect, CGContextRef cgContext, NSDictionary* aOptions)
|
|
|
|
|
{
|
|
|
|
|
static id appearance = GetAquaAppearance();
|
|
|
|
|
|
|
|
|
|
if (aRect.size.width * aRect.size.height > BITMAP_MAX_AREA) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (appearance && [appearance respondsToSelector:@selector(_drawInRect:context:options:)]) {
|
|
|
|
|
// Render through NSAppearance on Mac OS 10.10 and up. This will call
|
|
|
|
|
// CUIDraw with a CoreUI renderer that will give us the correct 10.10
|
|
|
|
|
// style. Calling CUIDraw directly with [NSWindow coreUIRenderer] still
|
|
|
|
|
// renders 10.9-style widgets on 10.10.
|
|
|
|
|
[appearance _drawInRect:aRect context:cgContext options:aOptions];
|
|
|
|
|
} else {
|
|
|
|
|
// 10.9 and below
|
|
|
|
|
RenderWithCoreUILegacy(aRect, cgContext, aOptions);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-10-13 09:58:40 -07:00
|
|
|
|
static float VerticalAlignFactor(nsIFrame *aFrame)
|
|
|
|
|
{
|
|
|
|
|
if (!aFrame)
|
|
|
|
|
return 0.5f; // default: center
|
|
|
|
|
|
2013-02-16 13:51:02 -08:00
|
|
|
|
const nsStyleCoord& va = aFrame->StyleTextReset()->mVerticalAlign;
|
2012-08-22 08:56:38 -07:00
|
|
|
|
uint8_t intval = (va.GetUnit() == eStyleUnit_Enumerated)
|
2008-10-13 09:58:40 -07:00
|
|
|
|
? va.GetIntValue()
|
|
|
|
|
: NS_STYLE_VERTICAL_ALIGN_MIDDLE;
|
|
|
|
|
switch (intval) {
|
|
|
|
|
case NS_STYLE_VERTICAL_ALIGN_TOP:
|
|
|
|
|
case NS_STYLE_VERTICAL_ALIGN_TEXT_TOP:
|
|
|
|
|
return 0.0f;
|
|
|
|
|
|
|
|
|
|
case NS_STYLE_VERTICAL_ALIGN_SUB:
|
|
|
|
|
case NS_STYLE_VERTICAL_ALIGN_SUPER:
|
|
|
|
|
case NS_STYLE_VERTICAL_ALIGN_MIDDLE:
|
|
|
|
|
case NS_STYLE_VERTICAL_ALIGN_MIDDLE_WITH_BASELINE:
|
|
|
|
|
return 0.5f;
|
|
|
|
|
|
|
|
|
|
case NS_STYLE_VERTICAL_ALIGN_BASELINE:
|
|
|
|
|
case NS_STYLE_VERTICAL_ALIGN_TEXT_BOTTOM:
|
|
|
|
|
case NS_STYLE_VERTICAL_ALIGN_BOTTOM:
|
|
|
|
|
return 1.0f;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
NS_NOTREACHED("invalid vertical-align");
|
|
|
|
|
return 0.5f;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-03-14 12:29:32 -07:00
|
|
|
|
// These are the sizes that Gecko needs to request to draw if it wants
|
|
|
|
|
// to get a standard-sized Aqua radio button drawn. Note that the rects
|
|
|
|
|
// that draw these are actually a little bigger.
|
2008-10-13 09:58:40 -07:00
|
|
|
|
static const CellRenderSettings radioSettings = {
|
|
|
|
|
{
|
|
|
|
|
NSMakeSize(11, 11), // mini
|
|
|
|
|
NSMakeSize(13, 13), // small
|
|
|
|
|
NSMakeSize(16, 16) // regular
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
NSZeroSize, NSZeroSize, NSZeroSize
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
{ // Leopard
|
|
|
|
|
{0, 0, 0, 0}, // mini
|
|
|
|
|
{0, 1, 1, 1}, // small
|
|
|
|
|
{0, 0, 0, 0} // regular
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
2008-03-14 12:29:32 -07:00
|
|
|
|
|
2008-10-13 09:58:40 -07:00
|
|
|
|
static const CellRenderSettings checkboxSettings = {
|
|
|
|
|
{
|
|
|
|
|
NSMakeSize(11, 11), // mini
|
|
|
|
|
NSMakeSize(13, 13), // small
|
|
|
|
|
NSMakeSize(16, 16) // regular
|
2008-03-14 12:29:32 -07:00
|
|
|
|
},
|
2008-10-13 09:58:40 -07:00
|
|
|
|
{
|
|
|
|
|
NSZeroSize, NSZeroSize, NSZeroSize
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
{ // Leopard
|
|
|
|
|
{0, 1, 0, 0}, // mini
|
|
|
|
|
{0, 1, 0, 1}, // small
|
|
|
|
|
{0, 1, 0, 1} // regular
|
|
|
|
|
}
|
2008-03-14 12:29:32 -07:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2008-03-04 12:51:54 -08:00
|
|
|
|
void
|
2011-09-28 23:19:26 -07:00
|
|
|
|
nsNativeThemeCocoa::DrawCheckboxOrRadio(CGContextRef cgContext, bool inCheckbox,
|
|
|
|
|
const HIRect& inBoxRect, bool inSelected,
|
2014-04-02 21:18:36 -07:00
|
|
|
|
EventStates inState, nsIFrame* aFrame)
|
2008-03-04 12:51:54 -08:00
|
|
|
|
{
|
|
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
|
2008-10-13 09:58:40 -07:00
|
|
|
|
NSButtonCell *cell = inCheckbox ? mCheckboxCell : mRadioButtonCell;
|
2009-01-29 23:19:41 -08:00
|
|
|
|
NSCellStateValue state = inSelected ? NSOnState : NSOffState;
|
|
|
|
|
|
|
|
|
|
// Check if we have an indeterminate checkbox
|
|
|
|
|
if (inCheckbox && GetIndeterminate(aFrame))
|
|
|
|
|
state = NSMixedState;
|
2008-03-04 12:51:54 -08:00
|
|
|
|
|
2010-09-27 18:25:18 -07:00
|
|
|
|
[cell setEnabled:!IsDisabled(aFrame, inState)];
|
2010-10-20 04:26:32 -07:00
|
|
|
|
[cell setShowsFirstResponder:inState.HasState(NS_EVENT_STATE_FOCUS)];
|
2009-01-29 23:19:41 -08:00
|
|
|
|
[cell setState:state];
|
2010-10-20 04:26:32 -07:00
|
|
|
|
[cell setHighlighted:inState.HasAllStates(NS_EVENT_STATE_ACTIVE | NS_EVENT_STATE_HOVER)];
|
2008-10-13 09:58:40 -07:00
|
|
|
|
[cell setControlTint:(FrameIsInActiveWindow(aFrame) ? [NSColor currentControlTint] : NSClearControlTint)];
|
2008-12-11 06:48:30 -08:00
|
|
|
|
|
|
|
|
|
// Ensure that the control is square.
|
2013-01-15 04:22:03 -08:00
|
|
|
|
float length = std::min(inBoxRect.size.width, inBoxRect.size.height);
|
2008-12-11 06:48:30 -08:00
|
|
|
|
HIRect drawRect = CGRectMake(inBoxRect.origin.x + (int)((inBoxRect.size.width - length) / 2.0f),
|
|
|
|
|
inBoxRect.origin.y + (int)((inBoxRect.size.height - length) / 2.0f),
|
|
|
|
|
length, length);
|
|
|
|
|
|
|
|
|
|
DrawCellWithSnapping(cell, cgContext, drawRect,
|
2008-10-13 09:58:40 -07:00
|
|
|
|
inCheckbox ? checkboxSettings : radioSettings,
|
2009-09-16 15:06:16 -07:00
|
|
|
|
VerticalAlignFactor(aFrame), mCellDrawView, NO);
|
2008-12-06 03:40:58 -08:00
|
|
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const CellRenderSettings searchFieldSettings = {
|
|
|
|
|
{
|
|
|
|
|
NSMakeSize(0, 16), // mini
|
|
|
|
|
NSMakeSize(0, 19), // small
|
|
|
|
|
NSMakeSize(0, 22) // regular
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
NSMakeSize(32, 0), // mini
|
|
|
|
|
NSMakeSize(38, 0), // small
|
|
|
|
|
NSMakeSize(44, 0) // regular
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
{ // Leopard
|
|
|
|
|
{0, 0, 0, 0}, // mini
|
|
|
|
|
{0, 0, 0, 0}, // small
|
|
|
|
|
{0, 0, 0, 0} // regular
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
nsNativeThemeCocoa::DrawSearchField(CGContextRef cgContext, const HIRect& inBoxRect,
|
2014-04-02 21:18:36 -07:00
|
|
|
|
nsIFrame* aFrame, EventStates inState)
|
2008-12-06 03:40:58 -08:00
|
|
|
|
{
|
|
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
|
2011-09-08 06:30:32 -07:00
|
|
|
|
ContextAwareSearchFieldCell* cell = mSearchFieldCell;
|
|
|
|
|
[cell setContext:aFrame];
|
2010-09-27 18:25:18 -07:00
|
|
|
|
[cell setEnabled:!IsDisabled(aFrame, inState)];
|
2010-09-19 18:16:49 -07:00
|
|
|
|
// NOTE: this could probably use inState
|
2008-12-06 03:40:58 -08:00
|
|
|
|
[cell setShowsFirstResponder:IsFocused(aFrame)];
|
|
|
|
|
|
|
|
|
|
DrawCellWithSnapping(cell, cgContext, inBoxRect, searchFieldSettings,
|
2009-09-16 15:06:16 -07:00
|
|
|
|
VerticalAlignFactor(aFrame), mCellDrawView,
|
2009-04-17 01:12:12 -07:00
|
|
|
|
IsFrameRTL(aFrame));
|
2008-03-04 12:51:54 -08:00
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
|
[cell setContext:nullptr];
|
2011-09-08 06:30:32 -07:00
|
|
|
|
|
2008-03-04 12:51:54 -08:00
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
|
|
|
|
}
|
2008-01-13 20:48:33 -08:00
|
|
|
|
|
2014-07-04 11:02:44 -07:00
|
|
|
|
static const NSSize kCheckmarkSize = NSMakeSize(11, 11);
|
2014-09-08 02:45:00 -07:00
|
|
|
|
static const NSSize kMenuarrowSize = nsCocoaFeatures::OnLionOrLater() ?
|
|
|
|
|
NSMakeSize(9, 10) : NSMakeSize(8, 10);
|
|
|
|
|
static const NSSize kMenuScrollArrowSize = NSMakeSize(10, 8);
|
2014-07-04 11:02:44 -07:00
|
|
|
|
static const NSString* kCheckmarkImage = @"image.MenuOnState";
|
2014-09-08 02:45:00 -07:00
|
|
|
|
static const NSString* kMenuarrowRightImage = @"image.MenuSubmenu";
|
|
|
|
|
static const NSString* kMenuarrowLeftImage = @"image.MenuSubmenuLeft";
|
|
|
|
|
static const NSString* kMenuDownScrollArrowImage = @"image.MenuScrollDown";
|
|
|
|
|
static const NSString* kMenuUpScrollArrowImage = @"image.MenuScrollUp";
|
2014-07-04 11:02:44 -07:00
|
|
|
|
static const CGFloat kMenuIconIndent = 6.0f;
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
nsNativeThemeCocoa::DrawMenuIcon(CGContextRef cgContext, const CGRect& aRect,
|
|
|
|
|
EventStates inState, nsIFrame* aFrame,
|
2014-09-08 02:45:00 -07:00
|
|
|
|
const NSSize& aIconSize, const NSString* aImageName,
|
|
|
|
|
bool aCenterHorizontally)
|
2014-07-04 11:02:44 -07:00
|
|
|
|
{
|
|
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
|
|
|
|
|
// Adjust size and position of our drawRect.
|
|
|
|
|
CGFloat paddingX = std::max(CGFloat(0.0), aRect.size.width - aIconSize.width);
|
|
|
|
|
CGFloat paddingY = std::max(CGFloat(0.0), aRect.size.height - aIconSize.height);
|
|
|
|
|
CGFloat paddingStartX = std::min(paddingX, kMenuIconIndent);
|
|
|
|
|
CGFloat paddingEndX = std::max(CGFloat(0.0), paddingX - kMenuIconIndent);
|
|
|
|
|
CGRect drawRect = CGRectMake(
|
2014-09-08 02:45:00 -07:00
|
|
|
|
aRect.origin.x + (aCenterHorizontally ? ceil(paddingX / 2) :
|
|
|
|
|
IsFrameRTL(aFrame) ? paddingEndX : paddingStartX),
|
2014-07-04 11:02:44 -07:00
|
|
|
|
aRect.origin.y + ceil(paddingY / 2),
|
|
|
|
|
aIconSize.width, aIconSize.height);
|
|
|
|
|
|
2014-08-26 10:15:48 -07:00
|
|
|
|
BOOL isDisabled = IsDisabled(aFrame, inState);
|
|
|
|
|
BOOL isActive = CheckBooleanAttr(aFrame, nsGkAtoms::menuactive);
|
|
|
|
|
|
|
|
|
|
// On 10.6 and at least on 10.7.0, Apple doesn’t seem to have implemented all
|
|
|
|
|
// keys and values used on 10.7.5 and later. We can however draw menu icons
|
|
|
|
|
// on earlier OS versions by using different keys/values.
|
|
|
|
|
BOOL otherKeysAndValues = !nsCocoaFeatures::OnLionOrLater() ||
|
|
|
|
|
(nsCocoaFeatures::OSXVersionMajor() == 10 &&
|
|
|
|
|
nsCocoaFeatures::OSXVersionMinor() == 7 &&
|
|
|
|
|
nsCocoaFeatures::OSXVersionBugFix() < 5);
|
|
|
|
|
|
|
|
|
|
// 2 states combined with 2 different backgroundTypeKeys on earlier versions.
|
|
|
|
|
NSString* state = isDisabled ? @"disabled" :
|
|
|
|
|
(isActive && !otherKeysAndValues) ? @"pressed" : @"normal";
|
|
|
|
|
NSString* backgroundTypeKey = !otherKeysAndValues ? @"kCUIBackgroundTypeMenu" :
|
|
|
|
|
!isDisabled && isActive ? @"backgroundTypeDark" : @"backgroundTypeLight";
|
|
|
|
|
|
|
|
|
|
NSMutableArray* keys = [NSMutableArray arrayWithObjects:@"backgroundTypeKey",
|
|
|
|
|
@"imageNameKey", @"state", @"widget", @"is.flipped", nil];
|
|
|
|
|
NSMutableArray* values = [NSMutableArray arrayWithObjects: backgroundTypeKey,
|
|
|
|
|
aImageName, state, @"image", [NSNumber numberWithBool:YES], nil];
|
|
|
|
|
|
|
|
|
|
if (otherKeysAndValues) { // Earlier versions used one more key-value pair.
|
|
|
|
|
[keys insertObject:@"imageIsGrayscaleKey" atIndex:1];
|
|
|
|
|
[values insertObject:[NSNumber numberWithBool:YES] atIndex:1];
|
|
|
|
|
}
|
2014-07-04 11:02:44 -07:00
|
|
|
|
|
2014-08-27 17:15:27 -07:00
|
|
|
|
RenderWithCoreUI(drawRect, cgContext,
|
|
|
|
|
[NSDictionary dictionaryWithObjects:values
|
|
|
|
|
forKeys:keys]);
|
2014-07-04 11:02:44 -07:00
|
|
|
|
|
|
|
|
|
#if DRAW_IN_FRAME_DEBUG
|
|
|
|
|
CGContextSetRGBFillColor(cgContext, 0.0, 0.0, 0.5, 0.25);
|
|
|
|
|
CGContextFillRect(cgContext, drawRect);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-27 09:12:16 -08:00
|
|
|
|
static const NSSize kHelpButtonSize = NSMakeSize(20, 20);
|
|
|
|
|
|
2009-01-12 11:22:59 -08:00
|
|
|
|
static const CellRenderSettings pushButtonSettings = {
|
|
|
|
|
{
|
|
|
|
|
NSMakeSize(0, 16), // mini
|
|
|
|
|
NSMakeSize(0, 19), // small
|
|
|
|
|
NSMakeSize(0, 22) // regular
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
NSMakeSize(18, 0), // mini
|
|
|
|
|
NSMakeSize(26, 0), // small
|
|
|
|
|
NSMakeSize(30, 0) // regular
|
2007-12-23 11:22:47 -08:00
|
|
|
|
},
|
2009-01-12 11:22:59 -08:00
|
|
|
|
{
|
|
|
|
|
{ // Leopard
|
|
|
|
|
{0, 0, 0, 0}, // mini
|
|
|
|
|
{4, 0, 4, 1}, // small
|
|
|
|
|
{5, 0, 5, 2} // regular
|
|
|
|
|
}
|
2007-12-23 11:22:47 -08:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2008-03-04 12:51:54 -08:00
|
|
|
|
// The height at which we start doing square buttons instead of rounded buttons
|
|
|
|
|
// Rounded buttons look bad if drawn at a height greater than 26, so at that point
|
|
|
|
|
// we switch over to doing square buttons which looks fine at any size.
|
|
|
|
|
#define DO_SQUARE_BUTTON_HEIGHT 26
|
|
|
|
|
|
2007-12-23 11:22:47 -08:00
|
|
|
|
void
|
2009-01-18 03:05:38 -08:00
|
|
|
|
nsNativeThemeCocoa::DrawPushButton(CGContextRef cgContext, const HIRect& inBoxRect,
|
2014-04-02 21:18:36 -07:00
|
|
|
|
EventStates inState, uint8_t aWidgetType,
|
2014-02-27 09:12:16 -08:00
|
|
|
|
nsIFrame* aFrame)
|
2007-12-23 11:22:47 -08:00
|
|
|
|
{
|
2008-02-20 17:01:27 -08:00
|
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
|
2008-09-22 01:57:42 -07:00
|
|
|
|
BOOL isActive = FrameIsInActiveWindow(aFrame);
|
2010-09-27 18:25:18 -07:00
|
|
|
|
BOOL isDisabled = IsDisabled(aFrame, inState);
|
2008-09-22 01:57:42 -07:00
|
|
|
|
|
2014-02-27 09:12:16 -08:00
|
|
|
|
NSButtonCell* cell = (aWidgetType == NS_THEME_MOZ_MAC_HELP_BUTTON) ? mHelpButtonCell : mPushButtonCell;
|
|
|
|
|
[cell setEnabled:!isDisabled];
|
|
|
|
|
[cell setHighlighted:isActive &&
|
|
|
|
|
inState.HasAllStates(NS_EVENT_STATE_ACTIVE | NS_EVENT_STATE_HOVER)];
|
|
|
|
|
[cell setShowsFirstResponder:inState.HasState(NS_EVENT_STATE_FOCUS) && !isDisabled && isActive];
|
2007-12-23 11:22:47 -08:00
|
|
|
|
|
2014-02-27 09:12:16 -08:00
|
|
|
|
if (aWidgetType == NS_THEME_MOZ_MAC_HELP_BUTTON) {
|
|
|
|
|
DrawCellWithScaling(cell, cgContext, inBoxRect, NSRegularControlSize,
|
|
|
|
|
NSZeroSize, kHelpButtonSize, NULL, mCellDrawView,
|
|
|
|
|
false); // Don't mirror icon in RTL.
|
|
|
|
|
} else {
|
|
|
|
|
// If the button is tall enough, draw the square button style so that
|
|
|
|
|
// buttons with non-standard content look good. Otherwise draw normal
|
|
|
|
|
// rounded aqua buttons.
|
|
|
|
|
if (inBoxRect.size.height > DO_SQUARE_BUTTON_HEIGHT) {
|
|
|
|
|
[cell setBezelStyle:NSShadowlessSquareBezelStyle];
|
|
|
|
|
DrawCellWithScaling(cell, cgContext, inBoxRect, NSRegularControlSize,
|
|
|
|
|
NSZeroSize, NSMakeSize(14, 0), NULL, mCellDrawView,
|
|
|
|
|
IsFrameRTL(aFrame));
|
|
|
|
|
} else {
|
|
|
|
|
[cell setBezelStyle:NSRoundedBezelStyle];
|
|
|
|
|
DrawCellWithSnapping(cell, cgContext, inBoxRect, pushButtonSettings, 0.5f,
|
|
|
|
|
mCellDrawView, IsFrameRTL(aFrame), 1.0f);
|
|
|
|
|
}
|
2007-12-23 11:22:47 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#if DRAW_IN_FRAME_DEBUG
|
2008-03-14 12:29:32 -07:00
|
|
|
|
CGContextSetRGBFillColor(cgContext, 0.0, 0.0, 0.5, 0.25);
|
2007-12-23 11:22:47 -08:00
|
|
|
|
CGContextFillRect(cgContext, inBoxRect);
|
|
|
|
|
#endif
|
2008-02-20 17:01:27 -08:00
|
|
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
2007-12-23 11:22:47 -08:00
|
|
|
|
}
|
|
|
|
|
|
2014-06-14 05:48:08 -07:00
|
|
|
|
void
|
|
|
|
|
nsNativeThemeCocoa::DrawFocusOutline(CGContextRef cgContext, const HIRect& inBoxRect,
|
|
|
|
|
EventStates inState, uint8_t aWidgetType,
|
|
|
|
|
nsIFrame* aFrame)
|
|
|
|
|
{
|
|
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
|
|
|
|
|
HIThemeFrameDrawInfo fdi;
|
|
|
|
|
fdi.version = 0;
|
|
|
|
|
fdi.kind = kHIThemeFrameTextFieldSquare;
|
|
|
|
|
fdi.state = kThemeStateActive;
|
|
|
|
|
fdi.isFocused = TRUE;
|
|
|
|
|
|
|
|
|
|
#if DRAW_IN_FRAME_DEBUG
|
|
|
|
|
CGContextSetRGBFillColor(cgContext, 0.0, 0.0, 0.5, 0.25);
|
|
|
|
|
CGContextFillRect(cgContext, inBoxRect);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
HIThemeDrawFrame(&inBoxRect, &fdi, cgContext, HITHEME_ORIENTATION);
|
|
|
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
|
|
|
|
}
|
|
|
|
|
|
2009-11-13 14:56:30 -08:00
|
|
|
|
typedef void (*RenderHIThemeControlFunction)(CGContextRef cgContext, const HIRect& aRenderRect, void* aData);
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
RenderTransformedHIThemeControl(CGContextRef aCGContext, const HIRect& aRect,
|
|
|
|
|
RenderHIThemeControlFunction aFunc, void* aData,
|
|
|
|
|
BOOL mirrorHorizontally = NO)
|
|
|
|
|
{
|
|
|
|
|
CGAffineTransform savedCTM = CGContextGetCTM(aCGContext);
|
|
|
|
|
CGContextTranslateCTM(aCGContext, aRect.origin.x, aRect.origin.y);
|
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
|
bool drawDirect;
|
2009-11-13 14:56:30 -08:00
|
|
|
|
HIRect drawRect = aRect;
|
|
|
|
|
drawRect.origin = CGPointZero;
|
|
|
|
|
|
|
|
|
|
if (!mirrorHorizontally && savedCTM.a == 1.0f && savedCTM.b == 0.0f &&
|
|
|
|
|
savedCTM.c == 0.0f && (savedCTM.d == 1.0f || savedCTM.d == -1.0f)) {
|
|
|
|
|
drawDirect = TRUE;
|
|
|
|
|
} else {
|
|
|
|
|
drawDirect = FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Fall back to no bitmap buffer if the area of our control (in pixels^2)
|
|
|
|
|
// is too large.
|
|
|
|
|
if (drawDirect || (aRect.size.width * aRect.size.height > BITMAP_MAX_AREA)) {
|
|
|
|
|
aFunc(aCGContext, drawRect, aData);
|
|
|
|
|
} else {
|
|
|
|
|
// Inflate the buffer to capture focus rings.
|
|
|
|
|
int w = ceil(drawRect.size.width) + 2 * MAX_FOCUS_RING_WIDTH;
|
|
|
|
|
int h = ceil(drawRect.size.height) + 2 * MAX_FOCUS_RING_WIDTH;
|
|
|
|
|
|
2012-08-13 09:45:57 -07:00
|
|
|
|
int backingScaleFactor = GetBackingScaleFactorForRendering(aCGContext);
|
2009-11-13 14:56:30 -08:00
|
|
|
|
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
|
2012-08-13 09:45:57 -07:00
|
|
|
|
CGContextRef bitmapctx = CGBitmapContextCreate(NULL,
|
|
|
|
|
w * backingScaleFactor,
|
|
|
|
|
h * backingScaleFactor,
|
|
|
|
|
8,
|
|
|
|
|
w * backingScaleFactor * 4,
|
2009-11-13 14:56:30 -08:00
|
|
|
|
colorSpace,
|
|
|
|
|
kCGImageAlphaPremultipliedFirst);
|
|
|
|
|
CGColorSpaceRelease(colorSpace);
|
|
|
|
|
|
2012-08-13 09:45:57 -07:00
|
|
|
|
CGContextScaleCTM(bitmapctx, backingScaleFactor, backingScaleFactor);
|
2009-11-13 14:56:30 -08:00
|
|
|
|
CGContextTranslateCTM(bitmapctx, MAX_FOCUS_RING_WIDTH, MAX_FOCUS_RING_WIDTH);
|
|
|
|
|
|
2014-09-18 01:52:35 -07:00
|
|
|
|
// Set the context's "base transform" to in order to get correctly-sized focus rings.
|
|
|
|
|
CGContextSetBaseCTM(bitmapctx, CGAffineTransformMakeScale(backingScaleFactor, backingScaleFactor));
|
|
|
|
|
|
2009-11-13 14:56:30 -08:00
|
|
|
|
// HITheme always wants to draw into a flipped context, or things
|
|
|
|
|
// get confused.
|
|
|
|
|
CGContextTranslateCTM(bitmapctx, 0.0f, aRect.size.height);
|
|
|
|
|
CGContextScaleCTM(bitmapctx, 1.0f, -1.0f);
|
|
|
|
|
|
|
|
|
|
aFunc(bitmapctx, drawRect, aData);
|
|
|
|
|
|
|
|
|
|
CGImageRef bitmap = CGBitmapContextCreateImage(bitmapctx);
|
|
|
|
|
|
|
|
|
|
CGAffineTransform ctm = CGContextGetCTM(aCGContext);
|
|
|
|
|
|
|
|
|
|
// We need to unflip, so that we can do a DrawImage without getting a flipped image.
|
|
|
|
|
CGContextTranslateCTM(aCGContext, 0.0f, aRect.size.height);
|
|
|
|
|
CGContextScaleCTM(aCGContext, 1.0f, -1.0f);
|
|
|
|
|
|
|
|
|
|
if (mirrorHorizontally) {
|
|
|
|
|
CGContextTranslateCTM(aCGContext, aRect.size.width, 0);
|
|
|
|
|
CGContextScaleCTM(aCGContext, -1.0f, 1.0f);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
HIRect inflatedDrawRect = CGRectMake(-MAX_FOCUS_RING_WIDTH, -MAX_FOCUS_RING_WIDTH, w, h);
|
|
|
|
|
CGContextDrawImage(aCGContext, inflatedDrawRect, bitmap);
|
|
|
|
|
|
|
|
|
|
CGContextSetCTM(aCGContext, ctm);
|
|
|
|
|
|
|
|
|
|
CGImageRelease(bitmap);
|
|
|
|
|
CGContextRelease(bitmapctx);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CGContextSetCTM(aCGContext, savedCTM);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
RenderButton(CGContextRef cgContext, const HIRect& aRenderRect, void* aData)
|
|
|
|
|
{
|
|
|
|
|
HIThemeButtonDrawInfo* bdi = (HIThemeButtonDrawInfo*)aData;
|
|
|
|
|
HIThemeDrawButton(&aRenderRect, bdi, cgContext, kHIThemeOrientationNormal, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
|
void
|
|
|
|
|
nsNativeThemeCocoa::DrawButton(CGContextRef cgContext, ThemeButtonKind inKind,
|
2011-09-28 23:19:26 -07:00
|
|
|
|
const HIRect& inBoxRect, bool inIsDefault,
|
2007-03-22 10:30:00 -07:00
|
|
|
|
ThemeButtonValue inValue, ThemeButtonAdornment inAdornment,
|
2014-04-02 21:18:36 -07:00
|
|
|
|
EventStates inState, nsIFrame* aFrame)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
{
|
2008-02-20 17:01:27 -08:00
|
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
|
2008-09-22 01:57:42 -07:00
|
|
|
|
BOOL isActive = FrameIsInActiveWindow(aFrame);
|
2010-09-27 18:25:18 -07:00
|
|
|
|
BOOL isDisabled = IsDisabled(aFrame, inState);
|
2008-09-22 01:57:42 -07:00
|
|
|
|
|
2007-05-02 16:47:53 -07:00
|
|
|
|
HIThemeButtonDrawInfo bdi;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
bdi.version = 0;
|
|
|
|
|
bdi.kind = inKind;
|
|
|
|
|
bdi.value = inValue;
|
|
|
|
|
bdi.adornment = inAdornment;
|
2007-05-02 16:47:53 -07:00
|
|
|
|
|
2010-09-27 18:25:18 -07:00
|
|
|
|
if (isDisabled) {
|
2007-03-22 10:30:00 -07:00
|
|
|
|
bdi.state = kThemeStateUnavailable;
|
2008-09-22 01:57:42 -07:00
|
|
|
|
}
|
2010-10-20 04:26:32 -07:00
|
|
|
|
else if (inState.HasAllStates(NS_EVENT_STATE_ACTIVE | NS_EVENT_STATE_HOVER)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
|
bdi.state = kThemeStatePressed;
|
2008-09-22 01:57:42 -07:00
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
if (inKind == kThemeArrowButton)
|
|
|
|
|
bdi.state = kThemeStateUnavailable; // these are always drawn as unavailable
|
2009-01-31 08:49:29 -08:00
|
|
|
|
else if (!isActive && inKind == kThemeListHeaderButton)
|
2008-09-22 01:57:42 -07:00
|
|
|
|
bdi.state = kThemeStateInactive;
|
|
|
|
|
else
|
|
|
|
|
bdi.state = kThemeStateActive;
|
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
2010-10-20 04:26:32 -07:00
|
|
|
|
if (inState.HasState(NS_EVENT_STATE_FOCUS) && isActive)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
bdi.adornment |= kThemeAdornmentFocus;
|
|
|
|
|
|
2010-09-27 18:25:18 -07:00
|
|
|
|
if (inIsDefault && !isDisabled && isActive &&
|
2010-10-20 04:26:32 -07:00
|
|
|
|
!inState.HasState(NS_EVENT_STATE_ACTIVE)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
|
bdi.adornment |= kThemeAdornmentDefault;
|
2009-01-18 03:05:38 -08:00
|
|
|
|
bdi.animation.time.start = 0;
|
|
|
|
|
bdi.animation.time.current = CFAbsoluteTimeGetCurrent();
|
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
2007-12-23 11:22:47 -08:00
|
|
|
|
HIRect drawFrame = inBoxRect;
|
2008-03-19 16:01:34 -07:00
|
|
|
|
|
2009-01-18 03:05:38 -08:00
|
|
|
|
if (inKind == kThemePushButton) {
|
|
|
|
|
drawFrame.size.height -= 2;
|
|
|
|
|
if (inBoxRect.size.height < pushButtonSettings.naturalSizes[smallControlSize].height) {
|
|
|
|
|
bdi.kind = kThemePushButtonMini;
|
|
|
|
|
}
|
|
|
|
|
else if (inBoxRect.size.height < pushButtonSettings.naturalSizes[regularControlSize].height) {
|
|
|
|
|
bdi.kind = kThemePushButtonSmall;
|
|
|
|
|
drawFrame.origin.y -= 1;
|
|
|
|
|
drawFrame.origin.x += 1;
|
|
|
|
|
drawFrame.size.width -= 2;
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-01-31 08:49:29 -08:00
|
|
|
|
else if (inKind == kThemeListHeaderButton) {
|
2008-11-27 14:14:54 -08:00
|
|
|
|
CGContextClipToRect(cgContext, inBoxRect);
|
|
|
|
|
// Always remove the top border.
|
|
|
|
|
drawFrame.origin.y -= 1;
|
|
|
|
|
drawFrame.size.height += 1;
|
|
|
|
|
// Remove the left border in LTR mode and the right border in RTL mode.
|
|
|
|
|
drawFrame.size.width += 1;
|
2011-09-28 23:19:26 -07:00
|
|
|
|
bool isLast = IsLastTreeHeaderCell(aFrame);
|
2008-11-27 14:14:54 -08:00
|
|
|
|
if (isLast)
|
|
|
|
|
drawFrame.size.width += 1; // Also remove the other border.
|
|
|
|
|
if (!IsFrameRTL(aFrame) || isLast)
|
|
|
|
|
drawFrame.origin.x -= 1;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
}
|
2007-05-02 16:47:53 -07:00
|
|
|
|
|
2009-11-13 14:56:30 -08:00
|
|
|
|
RenderTransformedHIThemeControl(cgContext, drawFrame, RenderButton, &bdi,
|
|
|
|
|
IsFrameRTL(aFrame));
|
2008-03-19 16:01:34 -07:00
|
|
|
|
|
2009-01-31 08:49:29 -08:00
|
|
|
|
#if DRAW_IN_FRAME_DEBUG
|
|
|
|
|
CGContextSetRGBFillColor(cgContext, 0.0, 0.0, 0.5, 0.25);
|
|
|
|
|
CGContextFillRect(cgContext, inBoxRect);
|
|
|
|
|
#endif
|
2008-03-19 16:01:34 -07:00
|
|
|
|
|
2009-01-31 08:49:29 -08:00
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
|
|
|
|
}
|
2008-03-19 16:01:34 -07:00
|
|
|
|
|
2009-01-31 08:49:29 -08:00
|
|
|
|
static const CellRenderSettings dropdownSettings = {
|
|
|
|
|
{
|
|
|
|
|
NSMakeSize(0, 16), // mini
|
|
|
|
|
NSMakeSize(0, 19), // small
|
|
|
|
|
NSMakeSize(0, 22) // regular
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
NSMakeSize(18, 0), // mini
|
|
|
|
|
NSMakeSize(38, 0), // small
|
|
|
|
|
NSMakeSize(44, 0) // regular
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
{ // Leopard
|
|
|
|
|
{1, 1, 2, 1}, // mini
|
|
|
|
|
{3, 0, 3, 1}, // small
|
|
|
|
|
{3, 0, 3, 0} // regular
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
2008-03-19 16:01:34 -07:00
|
|
|
|
|
2009-02-11 07:54:10 -08:00
|
|
|
|
static const CellRenderSettings editableMenulistSettings = {
|
|
|
|
|
{
|
|
|
|
|
NSMakeSize(0, 15), // mini
|
|
|
|
|
NSMakeSize(0, 18), // small
|
|
|
|
|
NSMakeSize(0, 21) // regular
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
NSMakeSize(18, 0), // mini
|
|
|
|
|
NSMakeSize(38, 0), // small
|
|
|
|
|
NSMakeSize(44, 0) // regular
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
{ // Leopard
|
|
|
|
|
{0, 0, 2, 2}, // mini
|
|
|
|
|
{0, 0, 3, 2}, // small
|
|
|
|
|
{0, 1, 3, 3} // regular
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2009-01-31 08:49:29 -08:00
|
|
|
|
void
|
|
|
|
|
nsNativeThemeCocoa::DrawDropdown(CGContextRef cgContext, const HIRect& inBoxRect,
|
2014-04-02 21:18:36 -07:00
|
|
|
|
EventStates inState, uint8_t aWidgetType,
|
2010-10-20 04:26:32 -07:00
|
|
|
|
nsIFrame* aFrame)
|
2009-01-31 08:49:29 -08:00
|
|
|
|
{
|
|
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
2008-03-19 16:01:34 -07:00
|
|
|
|
|
2009-08-10 14:23:50 -07:00
|
|
|
|
[mDropdownCell setPullsDown:(aWidgetType == NS_THEME_BUTTON)];
|
|
|
|
|
|
|
|
|
|
BOOL isEditable = (aWidgetType == NS_THEME_DROPDOWN_TEXTFIELD);
|
|
|
|
|
NSCell* cell = isEditable ? (NSCell*)mComboBoxCell : (NSCell*)mDropdownCell;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
2010-09-27 18:25:18 -07:00
|
|
|
|
[cell setEnabled:!IsDisabled(aFrame, inState)];
|
2010-10-20 04:26:32 -07:00
|
|
|
|
[cell setShowsFirstResponder:(IsFocused(aFrame) || inState.HasState(NS_EVENT_STATE_FOCUS))];
|
2009-12-11 14:01:38 -08:00
|
|
|
|
[cell setHighlighted:IsOpenButton(aFrame)];
|
2009-02-11 07:54:10 -08:00
|
|
|
|
[cell setControlTint:(FrameIsInActiveWindow(aFrame) ? [NSColor currentControlTint] : NSClearControlTint)];
|
|
|
|
|
|
2009-08-10 14:23:50 -07:00
|
|
|
|
const CellRenderSettings& settings = isEditable ? editableMenulistSettings : dropdownSettings;
|
2009-02-11 07:54:10 -08:00
|
|
|
|
DrawCellWithSnapping(cell, cgContext, inBoxRect, settings,
|
2009-09-16 15:06:16 -07:00
|
|
|
|
0.5f, mCellDrawView, IsFrameRTL(aFrame));
|
2008-02-20 17:01:27 -08:00
|
|
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
}
|
2007-04-10 17:25:11 -07:00
|
|
|
|
|
2013-12-05 08:20:34 -08:00
|
|
|
|
static const CellRenderSettings spinnerSettings = {
|
|
|
|
|
{
|
|
|
|
|
NSMakeSize(11, 16), // mini (width trimmed by 2px to reduce blank border)
|
|
|
|
|
NSMakeSize(15, 22), // small
|
|
|
|
|
NSMakeSize(19, 27) // regular
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
NSMakeSize(11, 16), // mini (width trimmed by 2px to reduce blank border)
|
|
|
|
|
NSMakeSize(15, 22), // small
|
|
|
|
|
NSMakeSize(19, 27) // regular
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
{ // Leopard
|
|
|
|
|
{0, 0, 0, 0}, // mini
|
|
|
|
|
{0, 0, 0, 0}, // small
|
|
|
|
|
{0, 0, 0, 0} // regular
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
|
void
|
|
|
|
|
nsNativeThemeCocoa::DrawSpinButtons(CGContextRef cgContext, ThemeButtonKind inKind,
|
2010-09-19 18:16:49 -07:00
|
|
|
|
const HIRect& inBoxRect, ThemeDrawState inDrawState,
|
2007-08-27 21:05:12 -07:00
|
|
|
|
ThemeButtonAdornment inAdornment,
|
2014-04-02 21:18:36 -07:00
|
|
|
|
EventStates inState, nsIFrame* aFrame)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
{
|
2008-02-20 17:01:27 -08:00
|
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
|
HIThemeButtonDrawInfo bdi;
|
|
|
|
|
bdi.version = 0;
|
|
|
|
|
bdi.kind = inKind;
|
|
|
|
|
bdi.value = kThemeButtonOff;
|
|
|
|
|
bdi.adornment = inAdornment;
|
|
|
|
|
|
2010-09-27 18:25:18 -07:00
|
|
|
|
if (IsDisabled(aFrame, inState))
|
2007-03-22 10:30:00 -07:00
|
|
|
|
bdi.state = kThemeStateUnavailable;
|
2008-09-22 01:57:42 -07:00
|
|
|
|
else
|
|
|
|
|
bdi.state = FrameIsInActiveWindow(aFrame) ? inDrawState : kThemeStateActive;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
|
|
HIThemeDrawButton(&inBoxRect, &bdi, cgContext, HITHEME_ORIENTATION, NULL);
|
2008-02-20 17:01:27 -08:00
|
|
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
}
|
|
|
|
|
|
2013-12-05 08:20:34 -08:00
|
|
|
|
void
|
|
|
|
|
nsNativeThemeCocoa::DrawSpinButton(CGContextRef cgContext,
|
|
|
|
|
ThemeButtonKind inKind,
|
|
|
|
|
const HIRect& inBoxRect,
|
|
|
|
|
ThemeDrawState inDrawState,
|
|
|
|
|
ThemeButtonAdornment inAdornment,
|
2014-04-02 21:18:36 -07:00
|
|
|
|
EventStates inState,
|
2013-12-05 08:20:34 -08:00
|
|
|
|
nsIFrame* aFrame,
|
|
|
|
|
uint8_t aWidgetType)
|
|
|
|
|
{
|
|
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
|
|
|
|
|
MOZ_ASSERT(aWidgetType == NS_THEME_SPINNER_UP_BUTTON ||
|
|
|
|
|
aWidgetType == NS_THEME_SPINNER_DOWN_BUTTON);
|
|
|
|
|
|
|
|
|
|
HIThemeButtonDrawInfo bdi;
|
|
|
|
|
bdi.version = 0;
|
|
|
|
|
bdi.kind = inKind;
|
|
|
|
|
bdi.value = kThemeButtonOff;
|
|
|
|
|
bdi.adornment = inAdornment;
|
|
|
|
|
|
|
|
|
|
if (IsDisabled(aFrame, inState))
|
|
|
|
|
bdi.state = kThemeStateUnavailable;
|
|
|
|
|
else
|
|
|
|
|
bdi.state = FrameIsInActiveWindow(aFrame) ? inDrawState : kThemeStateActive;
|
|
|
|
|
|
|
|
|
|
// Cocoa only allows kThemeIncDecButton to paint the up and down spin buttons
|
|
|
|
|
// together as a single unit (presumably because when one button is active,
|
|
|
|
|
// the appearance of both changes (in different ways)). Here we have to paint
|
|
|
|
|
// both buttons, using clip to hide the one we don't want to paint.
|
|
|
|
|
HIRect drawRect = inBoxRect;
|
|
|
|
|
drawRect.size.height *= 2;
|
|
|
|
|
if (aWidgetType == NS_THEME_SPINNER_DOWN_BUTTON) {
|
|
|
|
|
drawRect.origin.y -= inBoxRect.size.height;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Shift the drawing a little to the left, since cocoa paints with more
|
|
|
|
|
// blank space around the visual buttons than we'd like:
|
|
|
|
|
drawRect.origin.x -= 1;
|
|
|
|
|
|
|
|
|
|
CGContextSaveGState(cgContext);
|
|
|
|
|
CGContextClipToRect(cgContext, inBoxRect);
|
|
|
|
|
|
|
|
|
|
HIThemeDrawButton(&drawRect, &bdi, cgContext, HITHEME_ORIENTATION, NULL);
|
|
|
|
|
|
|
|
|
|
CGContextRestoreGState(cgContext);
|
|
|
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
|
|
|
|
}
|
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
|
void
|
|
|
|
|
nsNativeThemeCocoa::DrawFrame(CGContextRef cgContext, HIThemeFrameKind inKind,
|
2011-09-28 23:19:26 -07:00
|
|
|
|
const HIRect& inBoxRect, bool inDisabled,
|
2014-04-02 21:18:36 -07:00
|
|
|
|
EventStates inState)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
{
|
2008-02-20 17:01:27 -08:00
|
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
|
HIThemeFrameDrawInfo fdi;
|
|
|
|
|
fdi.version = 0;
|
|
|
|
|
fdi.kind = inKind;
|
2008-09-22 01:57:42 -07:00
|
|
|
|
|
|
|
|
|
// We don't ever set an inactive state for this because it doesn't
|
|
|
|
|
// look right (see other apps).
|
2010-09-27 18:25:18 -07:00
|
|
|
|
fdi.state = inDisabled ? kThemeStateUnavailable : kThemeStateActive;
|
2008-09-22 01:57:42 -07:00
|
|
|
|
|
2008-02-07 03:39:04 -08:00
|
|
|
|
// for some reason focus rings on listboxes draw incorrectly
|
|
|
|
|
if (inKind == kHIThemeFrameListBox)
|
|
|
|
|
fdi.isFocused = 0;
|
|
|
|
|
else
|
2010-10-20 04:26:32 -07:00
|
|
|
|
fdi.isFocused = inState.HasState(NS_EVENT_STATE_FOCUS);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
|
|
// HIThemeDrawFrame takes the rect for the content area of the frame, not
|
|
|
|
|
// the bounding rect for the frame. Here we reduce the size of the rect we
|
|
|
|
|
// will pass to make it the size of the content.
|
|
|
|
|
HIRect drawRect = inBoxRect;
|
|
|
|
|
if (inKind == kHIThemeFrameTextFieldSquare) {
|
|
|
|
|
SInt32 frameOutset = 0;
|
|
|
|
|
::GetThemeMetric(kThemeMetricEditTextFrameOutset, &frameOutset);
|
2007-08-28 00:21:04 -07:00
|
|
|
|
drawRect.origin.x += frameOutset;
|
|
|
|
|
drawRect.origin.y += frameOutset;
|
|
|
|
|
drawRect.size.width -= frameOutset * 2;
|
|
|
|
|
drawRect.size.height -= frameOutset * 2;
|
|
|
|
|
}
|
|
|
|
|
else if (inKind == kHIThemeFrameListBox) {
|
|
|
|
|
SInt32 frameOutset = 0;
|
|
|
|
|
::GetThemeMetric(kThemeMetricListBoxFrameOutset, &frameOutset);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
drawRect.origin.x += frameOutset;
|
|
|
|
|
drawRect.origin.y += frameOutset;
|
|
|
|
|
drawRect.size.width -= frameOutset * 2;
|
|
|
|
|
drawRect.size.height -= frameOutset * 2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#if DRAW_IN_FRAME_DEBUG
|
2008-03-14 12:29:32 -07:00
|
|
|
|
CGContextSetRGBFillColor(cgContext, 0.0, 0.0, 0.5, 0.25);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
CGContextFillRect(cgContext, inBoxRect);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
HIThemeDrawFrame(&drawRect, &fdi, cgContext, HITHEME_ORIENTATION);
|
2008-02-20 17:01:27 -08:00
|
|
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
}
|
|
|
|
|
|
2011-05-16 03:58:55 -07:00
|
|
|
|
static const CellRenderSettings progressSettings[2][2] = {
|
|
|
|
|
// Vertical progress bar.
|
2011-04-21 02:07:32 -07:00
|
|
|
|
{
|
2011-05-16 03:58:55 -07:00
|
|
|
|
// Determined settings.
|
2011-04-21 02:07:32 -07:00
|
|
|
|
{
|
2011-05-16 03:58:55 -07:00
|
|
|
|
{
|
|
|
|
|
NSZeroSize, // mini
|
|
|
|
|
NSMakeSize(10, 0), // small
|
|
|
|
|
NSMakeSize(16, 0) // regular
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
NSZeroSize, NSZeroSize, NSZeroSize
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
{ // Leopard
|
|
|
|
|
{0, 0, 0, 0}, // mini
|
|
|
|
|
{1, 1, 1, 1}, // small
|
|
|
|
|
{1, 1, 1, 1} // regular
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-04-21 02:07:32 -07:00
|
|
|
|
},
|
2011-05-16 03:58:55 -07:00
|
|
|
|
// There is no horizontal margin in regular undetermined size.
|
2011-04-21 02:07:32 -07:00
|
|
|
|
{
|
2011-05-16 03:58:55 -07:00
|
|
|
|
{
|
|
|
|
|
NSZeroSize, // mini
|
|
|
|
|
NSMakeSize(10, 0), // small
|
|
|
|
|
NSMakeSize(16, 0) // regular
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
NSZeroSize, NSZeroSize, NSZeroSize
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
{ // Leopard
|
|
|
|
|
{0, 0, 0, 0}, // mini
|
|
|
|
|
{1, 1, 1, 1}, // small
|
|
|
|
|
{1, 0, 1, 0} // regular
|
|
|
|
|
}
|
2011-04-21 02:07:32 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
2011-05-16 03:58:55 -07:00
|
|
|
|
// Horizontal progress bar.
|
2011-04-21 02:07:32 -07:00
|
|
|
|
{
|
2011-05-16 03:58:55 -07:00
|
|
|
|
// Determined settings.
|
2011-04-21 02:07:32 -07:00
|
|
|
|
{
|
2011-05-16 03:58:55 -07:00
|
|
|
|
{
|
|
|
|
|
NSZeroSize, // mini
|
|
|
|
|
NSMakeSize(0, 10), // small
|
|
|
|
|
NSMakeSize(0, 16) // regular
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
NSZeroSize, NSZeroSize, NSZeroSize
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
{ // Leopard
|
|
|
|
|
{0, 0, 0, 0}, // mini
|
|
|
|
|
{1, 1, 1, 1}, // small
|
|
|
|
|
{1, 1, 1, 1} // regular
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-04-21 02:07:32 -07:00
|
|
|
|
},
|
2011-05-16 03:58:55 -07:00
|
|
|
|
// There is no horizontal margin in regular undetermined size.
|
2011-04-21 02:07:32 -07:00
|
|
|
|
{
|
2011-05-16 03:58:55 -07:00
|
|
|
|
{
|
|
|
|
|
NSZeroSize, // mini
|
|
|
|
|
NSMakeSize(0, 10), // small
|
|
|
|
|
NSMakeSize(0, 16) // regular
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
NSZeroSize, NSZeroSize, NSZeroSize
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
{ // Leopard
|
|
|
|
|
{0, 0, 0, 0}, // mini
|
|
|
|
|
{1, 1, 1, 1}, // small
|
|
|
|
|
{0, 1, 0, 1} // regular
|
|
|
|
|
}
|
2011-04-21 02:07:32 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
2010-05-31 16:53:47 -07:00
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
|
void
|
2008-09-22 01:57:42 -07:00
|
|
|
|
nsNativeThemeCocoa::DrawProgress(CGContextRef cgContext, const HIRect& inBoxRect,
|
2011-09-28 23:19:26 -07:00
|
|
|
|
bool inIsIndeterminate, bool inIsHorizontal,
|
2011-04-21 02:06:51 -07:00
|
|
|
|
double inValue, double inMaxValue,
|
2008-10-30 02:34:23 -07:00
|
|
|
|
nsIFrame* aFrame)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
{
|
2008-02-20 17:01:27 -08:00
|
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
|
2011-04-21 02:07:32 -07:00
|
|
|
|
NSProgressBarCell* cell = mProgressBarCell;
|
2008-04-07 15:56:43 -07:00
|
|
|
|
|
2011-04-21 02:07:32 -07:00
|
|
|
|
[cell setValue:inValue];
|
|
|
|
|
[cell setMax:inMaxValue];
|
|
|
|
|
[cell setIndeterminate:inIsIndeterminate];
|
|
|
|
|
[cell setHorizontal:inIsHorizontal];
|
|
|
|
|
[cell setControlTint:(FrameIsInActiveWindow(aFrame) ? [NSColor currentControlTint]
|
|
|
|
|
: NSClearControlTint)];
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
2011-04-21 02:07:32 -07:00
|
|
|
|
DrawCellWithSnapping(cell, cgContext, inBoxRect,
|
2011-05-16 03:58:55 -07:00
|
|
|
|
progressSettings[inIsHorizontal][inIsIndeterminate],
|
2011-04-21 02:07:32 -07:00
|
|
|
|
VerticalAlignFactor(aFrame), mCellDrawView,
|
|
|
|
|
IsFrameRTL(aFrame));
|
2008-02-20 17:01:27 -08:00
|
|
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
}
|
|
|
|
|
|
2012-06-06 00:56:28 -07:00
|
|
|
|
static const CellRenderSettings meterSetting = {
|
|
|
|
|
{
|
|
|
|
|
NSMakeSize(0, 16), // mini
|
|
|
|
|
NSMakeSize(0, 16), // small
|
|
|
|
|
NSMakeSize(0, 16) // regular
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
NSZeroSize, NSZeroSize, NSZeroSize
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
{ // Leopard
|
|
|
|
|
{1, 1, 1, 1}, // mini
|
|
|
|
|
{1, 1, 1, 1}, // small
|
|
|
|
|
{1, 1, 1, 1} // regular
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
nsNativeThemeCocoa::DrawMeter(CGContextRef cgContext, const HIRect& inBoxRect,
|
|
|
|
|
nsIFrame* aFrame)
|
|
|
|
|
{
|
|
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK
|
|
|
|
|
|
|
|
|
|
NS_PRECONDITION(aFrame, "aFrame should not be null here!");
|
|
|
|
|
|
|
|
|
|
// When using -moz-meterbar on an non meter element, we will not be able to
|
|
|
|
|
// get all the needed information so we just draw an empty meter.
|
2013-08-01 15:24:24 -07:00
|
|
|
|
nsIContent* content = aFrame->GetContent();
|
|
|
|
|
if (!(content && content->IsHTML(nsGkAtoms::meter))) {
|
2012-06-06 00:56:28 -07:00
|
|
|
|
DrawCellWithSnapping(mMeterBarCell, cgContext, inBoxRect,
|
|
|
|
|
meterSetting, VerticalAlignFactor(aFrame),
|
|
|
|
|
mCellDrawView, IsFrameRTL(aFrame));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-01 15:24:24 -07:00
|
|
|
|
HTMLMeterElement* meterElement = static_cast<HTMLMeterElement*>(content);
|
|
|
|
|
double value = meterElement->Value();
|
|
|
|
|
double min = meterElement->Min();
|
|
|
|
|
double max = meterElement->Max();
|
2012-06-06 00:56:28 -07:00
|
|
|
|
|
|
|
|
|
NSLevelIndicatorCell* cell = mMeterBarCell;
|
|
|
|
|
|
|
|
|
|
[cell setMinValue:min];
|
|
|
|
|
[cell setMaxValue:max];
|
|
|
|
|
[cell setDoubleValue:value];
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The way HTML and Cocoa defines the meter/indicator widget are different.
|
|
|
|
|
* So, we are going to use a trick to get the Cocoa widget showing what we
|
|
|
|
|
* are expecting: we set the warningValue or criticalValue to the current
|
|
|
|
|
* value when we want to have the widget to be in the warning or critical
|
|
|
|
|
* state.
|
|
|
|
|
*/
|
2014-04-02 21:18:36 -07:00
|
|
|
|
EventStates states = aFrame->GetContent()->AsElement()->State();
|
2012-06-06 00:56:28 -07:00
|
|
|
|
|
|
|
|
|
// Reset previously set warning and critical values.
|
|
|
|
|
[cell setWarningValue:max+1];
|
|
|
|
|
[cell setCriticalValue:max+1];
|
|
|
|
|
|
|
|
|
|
if (states.HasState(NS_EVENT_STATE_SUB_OPTIMUM)) {
|
|
|
|
|
[cell setWarningValue:value];
|
|
|
|
|
} else if (states.HasState(NS_EVENT_STATE_SUB_SUB_OPTIMUM)) {
|
|
|
|
|
[cell setCriticalValue:value];
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-06 00:58:00 -07:00
|
|
|
|
HIRect rect = CGRectStandardize(inBoxRect);
|
|
|
|
|
BOOL vertical = IsVerticalMeter(aFrame);
|
|
|
|
|
|
|
|
|
|
CGContextSaveGState(cgContext);
|
|
|
|
|
|
|
|
|
|
if (vertical) {
|
|
|
|
|
/**
|
|
|
|
|
* Cocoa doesn't provide a vertical meter bar so to show one, we have to
|
|
|
|
|
* show a rotated horizontal meter bar.
|
|
|
|
|
* Given that we want to show a vertical meter bar, we assume that the rect
|
|
|
|
|
* has vertical dimensions but we can't correctly draw a meter widget inside
|
|
|
|
|
* such a rectangle so we need to inverse width and height (and re-position)
|
|
|
|
|
* to get a rectangle with horizontal dimensions.
|
|
|
|
|
* Finally, we want to show a vertical meter so we want to rotate the result
|
|
|
|
|
* so it is vertical. We do that by changing the context.
|
|
|
|
|
*/
|
|
|
|
|
CGFloat tmp = rect.size.width;
|
|
|
|
|
rect.size.width = rect.size.height;
|
|
|
|
|
rect.size.height = tmp;
|
|
|
|
|
rect.origin.x += rect.size.height / 2.f - rect.size.width / 2.f;
|
|
|
|
|
rect.origin.y += rect.size.width / 2.f - rect.size.height / 2.f;
|
|
|
|
|
|
|
|
|
|
CGContextTranslateCTM(cgContext, CGRectGetMidX(rect), CGRectGetMidY(rect));
|
|
|
|
|
CGContextRotateCTM(cgContext, -M_PI / 2.f);
|
|
|
|
|
CGContextTranslateCTM(cgContext, -CGRectGetMidX(rect), -CGRectGetMidY(rect));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DrawCellWithSnapping(cell, cgContext, rect,
|
2012-06-06 00:56:28 -07:00
|
|
|
|
meterSetting, VerticalAlignFactor(aFrame),
|
2012-06-06 00:58:00 -07:00
|
|
|
|
mCellDrawView, !vertical && IsFrameRTL(aFrame));
|
|
|
|
|
|
|
|
|
|
CGContextRestoreGState(cgContext);
|
2012-06-06 00:56:28 -07:00
|
|
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK
|
|
|
|
|
}
|
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
|
void
|
2008-09-22 01:57:42 -07:00
|
|
|
|
nsNativeThemeCocoa::DrawTabPanel(CGContextRef cgContext, const HIRect& inBoxRect,
|
|
|
|
|
nsIFrame* aFrame)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
{
|
2008-02-20 17:01:27 -08:00
|
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
|
HIThemeTabPaneDrawInfo tpdi;
|
|
|
|
|
|
2008-11-27 14:16:13 -08:00
|
|
|
|
tpdi.version = 1;
|
2008-09-22 01:57:42 -07:00
|
|
|
|
tpdi.state = FrameIsInActiveWindow(aFrame) ? kThemeStateActive : kThemeStateInactive;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
tpdi.direction = kThemeTabNorth;
|
|
|
|
|
tpdi.size = kHIThemeTabSizeNormal;
|
2008-11-27 14:16:13 -08:00
|
|
|
|
tpdi.kind = kHIThemeTabKindNormal;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
|
|
HIThemeDrawTabPane(&inBoxRect, &tpdi, cgContext, HITHEME_ORIENTATION);
|
2008-02-20 17:01:27 -08:00
|
|
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
nsNativeThemeCocoa::DrawScale(CGContextRef cgContext, const HIRect& inBoxRect,
|
2014-04-02 21:18:36 -07:00
|
|
|
|
EventStates inState, bool inIsVertical,
|
2012-08-22 08:56:38 -07:00
|
|
|
|
bool inIsReverse, int32_t inCurrentValue,
|
|
|
|
|
int32_t inMinValue, int32_t inMaxValue,
|
2010-09-19 18:16:49 -07:00
|
|
|
|
nsIFrame* aFrame)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
{
|
2008-02-20 17:01:27 -08:00
|
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
|
HIThemeTrackDrawInfo tdi;
|
|
|
|
|
|
|
|
|
|
tdi.version = 0;
|
|
|
|
|
tdi.kind = kThemeMediumSlider;
|
|
|
|
|
tdi.bounds = inBoxRect;
|
|
|
|
|
tdi.min = inMinValue;
|
|
|
|
|
tdi.max = inMaxValue;
|
|
|
|
|
tdi.value = inCurrentValue;
|
|
|
|
|
tdi.attributes = kThemeTrackShowThumb;
|
|
|
|
|
if (!inIsVertical)
|
|
|
|
|
tdi.attributes |= kThemeTrackHorizontal;
|
2007-04-09 15:39:57 -07:00
|
|
|
|
if (inIsReverse)
|
|
|
|
|
tdi.attributes |= kThemeTrackRightToLeft;
|
2010-10-20 04:26:32 -07:00
|
|
|
|
if (inState.HasState(NS_EVENT_STATE_FOCUS))
|
2007-03-22 10:30:00 -07:00
|
|
|
|
tdi.attributes |= kThemeTrackHasFocus;
|
2010-09-27 18:25:18 -07:00
|
|
|
|
if (IsDisabled(aFrame, inState))
|
2008-09-22 01:57:42 -07:00
|
|
|
|
tdi.enableState = kThemeTrackDisabled;
|
|
|
|
|
else
|
|
|
|
|
tdi.enableState = FrameIsInActiveWindow(aFrame) ? kThemeTrackActive : kThemeTrackInactive;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
tdi.trackInfo.slider.thumbDir = kThemeThumbPlain;
|
|
|
|
|
tdi.trackInfo.slider.pressState = 0;
|
|
|
|
|
|
|
|
|
|
HIThemeDrawTrack(&tdi, NULL, cgContext, HITHEME_ORIENTATION);
|
2008-02-20 17:01:27 -08:00
|
|
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
}
|
|
|
|
|
|
2011-08-08 07:42:45 -07:00
|
|
|
|
nsIFrame*
|
|
|
|
|
nsNativeThemeCocoa::SeparatorResponsibility(nsIFrame* aBefore, nsIFrame* aAfter)
|
|
|
|
|
{
|
|
|
|
|
// Usually a separator is drawn by the segment to the right of the
|
|
|
|
|
// separator, but pressed and selected segments have higher priority.
|
|
|
|
|
if (!aBefore || !aAfter)
|
2012-07-30 07:20:58 -07:00
|
|
|
|
return nullptr;
|
2011-08-08 07:42:45 -07:00
|
|
|
|
if (IsSelectedButton(aAfter))
|
|
|
|
|
return aAfter;
|
|
|
|
|
if (IsSelectedButton(aBefore) || IsPressedButton(aBefore))
|
|
|
|
|
return aBefore;
|
|
|
|
|
return aAfter;
|
|
|
|
|
}
|
2008-02-20 17:01:27 -08:00
|
|
|
|
|
2011-08-08 07:42:45 -07:00
|
|
|
|
CGRect
|
|
|
|
|
nsNativeThemeCocoa::SeparatorAdjustedRect(CGRect aRect, nsIFrame* aLeft,
|
|
|
|
|
nsIFrame* aCurrent, nsIFrame* aRight)
|
2011-08-08 07:42:45 -07:00
|
|
|
|
{
|
2011-08-08 07:42:45 -07:00
|
|
|
|
// A separator between two segments should always be located in the leftmost
|
|
|
|
|
// pixel column of the segment to the right of the separator, regardless of
|
|
|
|
|
// who ends up drawing it.
|
|
|
|
|
// CoreUI draws the separators inside the drawing rect.
|
|
|
|
|
if (aLeft && SeparatorResponsibility(aLeft, aCurrent) == aLeft) {
|
|
|
|
|
// The left button draws the separator, so we need to make room for it.
|
|
|
|
|
aRect.origin.x += 1;
|
|
|
|
|
aRect.size.width -= 1;
|
|
|
|
|
}
|
|
|
|
|
if (SeparatorResponsibility(aCurrent, aRight) == aCurrent) {
|
|
|
|
|
// We draw the right separator, so we need to extend the draw rect into the
|
|
|
|
|
// segment to our right.
|
|
|
|
|
aRect.size.width += 1;
|
|
|
|
|
}
|
|
|
|
|
return aRect;
|
|
|
|
|
}
|
2010-09-27 18:25:18 -07:00
|
|
|
|
|
2011-08-08 07:42:45 -07:00
|
|
|
|
static NSString* ToolbarButtonPosition(BOOL aIsFirst, BOOL aIsLast)
|
|
|
|
|
{
|
|
|
|
|
if (aIsFirst) {
|
|
|
|
|
if (aIsLast)
|
|
|
|
|
return @"kCUISegmentPositionOnly";
|
|
|
|
|
return @"kCUISegmentPositionFirst";
|
|
|
|
|
}
|
|
|
|
|
if (aIsLast)
|
|
|
|
|
return @"kCUISegmentPositionLast";
|
|
|
|
|
return @"kCUISegmentPositionMiddle";
|
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
2011-08-08 07:42:45 -07:00
|
|
|
|
struct SegmentedControlRenderSettings {
|
|
|
|
|
const CGFloat* heights;
|
|
|
|
|
const NSString* widgetName;
|
|
|
|
|
const BOOL ignoresPressedWhenSelected;
|
|
|
|
|
const BOOL isToolbarControl;
|
|
|
|
|
};
|
2011-08-08 07:42:45 -07:00
|
|
|
|
|
2011-08-08 07:42:45 -07:00
|
|
|
|
static const CGFloat tabHeights[3] = { 17, 20, 23 };
|
2008-11-27 14:16:13 -08:00
|
|
|
|
|
2011-08-08 07:42:45 -07:00
|
|
|
|
static const SegmentedControlRenderSettings tabRenderSettings = {
|
|
|
|
|
tabHeights, @"tab", YES, NO
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static const CGFloat toolbarButtonHeights[3] = { 15, 18, 22 };
|
2011-08-08 07:42:45 -07:00
|
|
|
|
|
2011-08-08 07:42:45 -07:00
|
|
|
|
static const SegmentedControlRenderSettings toolbarButtonRenderSettings = {
|
|
|
|
|
toolbarButtonHeights, @"kCUIWidgetButtonSegmentedSCurve", NO, YES
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
nsNativeThemeCocoa::DrawSegment(CGContextRef cgContext, const HIRect& inBoxRect,
|
2014-04-02 21:18:36 -07:00
|
|
|
|
EventStates inState, nsIFrame* aFrame,
|
2011-08-08 07:42:45 -07:00
|
|
|
|
const SegmentedControlRenderSettings& aSettings)
|
|
|
|
|
{
|
|
|
|
|
BOOL isActive = IsActive(aFrame, aSettings.isToolbarControl);
|
|
|
|
|
BOOL isFocused = inState.HasState(NS_EVENT_STATE_FOCUS);
|
|
|
|
|
BOOL isSelected = IsSelectedButton(aFrame);
|
|
|
|
|
BOOL isPressed = IsPressedButton(aFrame);
|
|
|
|
|
if (isSelected && aSettings.ignoresPressedWhenSelected) {
|
|
|
|
|
isPressed = NO;
|
2008-11-27 14:16:13 -08:00
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
2011-08-08 07:42:45 -07:00
|
|
|
|
BOOL isRTL = IsFrameRTL(aFrame);
|
|
|
|
|
nsIFrame* left = GetAdjacentSiblingFrameWithSameAppearance(aFrame, isRTL);
|
|
|
|
|
nsIFrame* right = GetAdjacentSiblingFrameWithSameAppearance(aFrame, !isRTL);
|
|
|
|
|
CGRect drawRect = SeparatorAdjustedRect(inBoxRect, left, aFrame, right);
|
|
|
|
|
BOOL drawLeftSeparator = SeparatorResponsibility(left, aFrame) == aFrame;
|
|
|
|
|
BOOL drawRightSeparator = SeparatorResponsibility(aFrame, right) == aFrame;
|
|
|
|
|
NSControlSize controlSize = FindControlSize(drawRect.size.height, aSettings.heights, 4.0f);
|
2008-02-20 17:01:27 -08:00
|
|
|
|
|
2014-08-27 17:15:27 -07:00
|
|
|
|
RenderWithCoreUI(drawRect, cgContext, [NSDictionary dictionaryWithObjectsAndKeys:
|
2011-08-08 07:42:45 -07:00
|
|
|
|
aSettings.widgetName, @"widget",
|
2014-08-27 17:15:27 -07:00
|
|
|
|
(isActive ? @"kCUIPresentationStateActiveKey" : @"kCUIPresentationStateInactive"), @"kCUIPresentationStateKey",
|
2011-08-08 07:42:45 -07:00
|
|
|
|
ToolbarButtonPosition(!left, !right), @"kCUIPositionKey",
|
|
|
|
|
[NSNumber numberWithBool:drawLeftSeparator], @"kCUISegmentLeadingSeparatorKey",
|
|
|
|
|
[NSNumber numberWithBool:drawRightSeparator], @"kCUISegmentTrailingSeparatorKey",
|
|
|
|
|
[NSNumber numberWithBool:isSelected], @"value",
|
|
|
|
|
(isPressed ? @"pressed" : (isActive ? @"normal" : @"inactive")), @"state",
|
|
|
|
|
[NSNumber numberWithBool:isFocused], @"focus",
|
|
|
|
|
CUIControlSizeForCocoaSize(controlSize), @"size",
|
|
|
|
|
[NSNumber numberWithBool:YES], @"is.flipped",
|
|
|
|
|
@"up", @"direction",
|
2014-08-27 17:15:27 -07:00
|
|
|
|
nil]);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
}
|
|
|
|
|
|
2008-03-04 12:51:54 -08:00
|
|
|
|
static inline UInt8
|
2014-04-02 21:18:36 -07:00
|
|
|
|
ConvertToPressState(EventStates aButtonState, UInt8 aPressState)
|
2007-04-10 17:25:11 -07:00
|
|
|
|
{
|
|
|
|
|
// If the button is pressed, return the press state passed in. Otherwise, return 0.
|
2010-10-20 04:26:32 -07:00
|
|
|
|
return aButtonState.HasAllStates(NS_EVENT_STATE_ACTIVE | NS_EVENT_STATE_HOVER) ? aPressState : 0;
|
2007-04-10 17:25:11 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2014-04-02 21:18:36 -07:00
|
|
|
|
nsNativeThemeCocoa::GetScrollbarPressStates(nsIFrame* aFrame,
|
|
|
|
|
EventStates aButtonStates[])
|
2007-04-10 17:25:11 -07:00
|
|
|
|
{
|
|
|
|
|
static nsIContent::AttrValuesArray attributeValues[] = {
|
2011-10-14 11:11:22 -07:00
|
|
|
|
&nsGkAtoms::scrollbarUpTop,
|
|
|
|
|
&nsGkAtoms::scrollbarDownTop,
|
|
|
|
|
&nsGkAtoms::scrollbarUpBottom,
|
|
|
|
|
&nsGkAtoms::scrollbarDownBottom,
|
2012-07-30 07:20:58 -07:00
|
|
|
|
nullptr
|
2007-04-10 17:25:11 -07:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Get the state of any scrollbar buttons in our child frames
|
2011-08-24 13:54:30 -07:00
|
|
|
|
for (nsIFrame *childFrame = aFrame->GetFirstPrincipalChild();
|
2007-04-10 17:25:11 -07:00
|
|
|
|
childFrame;
|
|
|
|
|
childFrame = childFrame->GetNextSibling()) {
|
|
|
|
|
|
|
|
|
|
nsIContent *childContent = childFrame->GetContent();
|
|
|
|
|
if (!childContent) continue;
|
2012-08-22 08:56:38 -07:00
|
|
|
|
int32_t attrIndex = childContent->FindAttrValueIn(kNameSpaceID_None, nsGkAtoms::sbattr,
|
2007-04-10 17:25:11 -07:00
|
|
|
|
attributeValues, eCaseMatters);
|
|
|
|
|
if (attrIndex < 0) continue;
|
|
|
|
|
|
2010-10-20 04:26:32 -07:00
|
|
|
|
aButtonStates[attrIndex] = GetContentState(childFrame, NS_THEME_BUTTON);
|
2007-04-10 17:25:11 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-07-03 13:05:15 -07:00
|
|
|
|
// Both of the following sets of numbers were derived by loading the testcase in
|
|
|
|
|
// bmo bug 380185 in Safari and observing its behavior for various heights of scrollbar.
|
2007-07-03 11:49:44 -07:00
|
|
|
|
// These magic numbers are the minimum sizes we can draw a scrollbar and still
|
|
|
|
|
// have room for everything to display, including the thumb
|
|
|
|
|
#define MIN_SCROLLBAR_SIZE_WITH_THUMB 61
|
|
|
|
|
#define MIN_SMALL_SCROLLBAR_SIZE_WITH_THUMB 49
|
|
|
|
|
// And these are the minimum sizes if we don't draw the thumb
|
|
|
|
|
#define MIN_SCROLLBAR_SIZE 56
|
|
|
|
|
#define MIN_SMALL_SCROLLBAR_SIZE 46
|
|
|
|
|
|
2007-04-10 17:25:11 -07:00
|
|
|
|
void
|
|
|
|
|
nsNativeThemeCocoa::GetScrollbarDrawInfo(HIThemeTrackDrawInfo& aTdi, nsIFrame *aFrame,
|
2011-09-28 23:19:26 -07:00
|
|
|
|
const CGSize& aSize, bool aShouldGetButtonStates)
|
2007-04-10 17:25:11 -07:00
|
|
|
|
{
|
2008-02-20 17:01:27 -08:00
|
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
|
int32_t curpos = CheckIntAttr(aFrame, nsGkAtoms::curpos, 0);
|
|
|
|
|
int32_t minpos = CheckIntAttr(aFrame, nsGkAtoms::minpos, 0);
|
|
|
|
|
int32_t maxpos = CheckIntAttr(aFrame, nsGkAtoms::maxpos, 100);
|
|
|
|
|
int32_t thumbSize = CheckIntAttr(aFrame, nsGkAtoms::pageincrement, 10);
|
2007-04-10 17:25:11 -07:00
|
|
|
|
|
2011-10-14 11:11:22 -07:00
|
|
|
|
bool isHorizontal = aFrame->GetContent()->AttrValueIs(kNameSpaceID_None, nsGkAtoms::orient,
|
|
|
|
|
nsGkAtoms::horizontal, eCaseMatters);
|
2013-02-16 13:51:02 -08:00
|
|
|
|
bool isSmall = aFrame->StyleDisplay()->mAppearance == NS_THEME_SCROLLBAR_SMALL;
|
2007-04-10 17:25:11 -07:00
|
|
|
|
|
|
|
|
|
aTdi.version = 0;
|
|
|
|
|
aTdi.kind = isSmall ? kThemeSmallScrollBar : kThemeMediumScrollBar;
|
2009-09-27 14:58:15 -07:00
|
|
|
|
aTdi.bounds.origin = CGPointZero;
|
|
|
|
|
aTdi.bounds.size = aSize;
|
2007-04-10 17:25:11 -07:00
|
|
|
|
aTdi.min = minpos;
|
|
|
|
|
aTdi.max = maxpos;
|
|
|
|
|
aTdi.value = curpos;
|
2007-07-03 11:49:44 -07:00
|
|
|
|
aTdi.attributes = 0;
|
2007-10-05 14:01:42 -07:00
|
|
|
|
aTdi.enableState = kThemeTrackActive;
|
2007-04-10 17:25:11 -07:00
|
|
|
|
if (isHorizontal)
|
|
|
|
|
aTdi.attributes |= kThemeTrackHorizontal;
|
|
|
|
|
|
2008-03-26 22:36:20 -07:00
|
|
|
|
aTdi.trackInfo.scrollbar.viewsize = (SInt32)thumbSize;
|
2007-04-10 17:25:11 -07:00
|
|
|
|
|
2008-09-22 01:57:42 -07:00
|
|
|
|
// This should be done early on so things like "kThemeTrackNothingToScroll" can
|
|
|
|
|
// override the active enable state.
|
|
|
|
|
aTdi.enableState = FrameIsInActiveWindow(aFrame) ? kThemeTrackActive : kThemeTrackInactive;
|
|
|
|
|
|
2008-03-04 12:51:54 -08:00
|
|
|
|
/* Only display features if we have enough room for them.
|
|
|
|
|
* Gecko still maintains the scrollbar info; this is just a visual issue (bug 380185).
|
|
|
|
|
*/
|
2012-08-22 08:56:38 -07:00
|
|
|
|
int32_t longSideLength = (int32_t)(isHorizontal ? (aSize.width) : (aSize.height));
|
2007-07-03 13:05:15 -07:00
|
|
|
|
if (longSideLength >= (isSmall ? MIN_SMALL_SCROLLBAR_SIZE_WITH_THUMB : MIN_SCROLLBAR_SIZE_WITH_THUMB)) {
|
2007-07-03 11:49:44 -07:00
|
|
|
|
aTdi.attributes |= kThemeTrackShowThumb;
|
|
|
|
|
}
|
2007-07-03 13:05:15 -07:00
|
|
|
|
else if (longSideLength < (isSmall ? MIN_SMALL_SCROLLBAR_SIZE : MIN_SCROLLBAR_SIZE)) {
|
2007-07-03 11:49:44 -07:00
|
|
|
|
aTdi.enableState = kThemeTrackNothingToScroll;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2009-03-09 15:03:16 -07:00
|
|
|
|
aTdi.trackInfo.scrollbar.pressState = 0;
|
|
|
|
|
|
2011-05-16 10:56:03 -07:00
|
|
|
|
// Only go get these scrollbar button states if we need it. For example,
|
|
|
|
|
// there's no reason to look up scrollbar button states when we're only
|
|
|
|
|
// creating a TrackDrawInfo to determine the size of the thumb. There's
|
|
|
|
|
// also no reason to do this on Lion or later, whose scrollbars have no
|
|
|
|
|
// arrow buttons.
|
2012-05-17 00:53:20 -07:00
|
|
|
|
if (aShouldGetButtonStates && !nsCocoaFeatures::OnLionOrLater()) {
|
2014-04-02 21:18:36 -07:00
|
|
|
|
EventStates buttonStates[4];
|
2007-04-10 17:25:11 -07:00
|
|
|
|
GetScrollbarPressStates(aFrame, buttonStates);
|
2009-09-22 01:01:35 -07:00
|
|
|
|
NSString *buttonPlacement = [[NSUserDefaults standardUserDefaults] objectForKey:@"AppleScrollBarVariant"];
|
|
|
|
|
// It seems that unless all four buttons are showing, kThemeTopOutsideArrowPressed is the correct constant for
|
|
|
|
|
// the up scrollbar button.
|
|
|
|
|
if ([buttonPlacement isEqualToString:@"DoubleBoth"]) {
|
2007-04-10 17:25:11 -07:00
|
|
|
|
aTdi.trackInfo.scrollbar.pressState = ConvertToPressState(buttonStates[0], kThemeTopOutsideArrowPressed) |
|
|
|
|
|
ConvertToPressState(buttonStates[1], kThemeTopInsideArrowPressed) |
|
|
|
|
|
ConvertToPressState(buttonStates[2], kThemeBottomInsideArrowPressed) |
|
|
|
|
|
ConvertToPressState(buttonStates[3], kThemeBottomOutsideArrowPressed);
|
|
|
|
|
} else {
|
|
|
|
|
aTdi.trackInfo.scrollbar.pressState = ConvertToPressState(buttonStates[0], kThemeTopOutsideArrowPressed) |
|
2008-04-08 23:38:01 -07:00
|
|
|
|
ConvertToPressState(buttonStates[1], kThemeBottomOutsideArrowPressed) |
|
2007-04-10 17:25:11 -07:00
|
|
|
|
ConvertToPressState(buttonStates[2], kThemeTopOutsideArrowPressed) |
|
|
|
|
|
ConvertToPressState(buttonStates[3], kThemeBottomOutsideArrowPressed);
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-02-20 17:01:27 -08:00
|
|
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
2007-04-10 17:25:11 -07:00
|
|
|
|
}
|
|
|
|
|
|
2009-09-27 14:58:15 -07:00
|
|
|
|
static void
|
2009-11-13 14:56:30 -08:00
|
|
|
|
RenderScrollbar(CGContextRef cgContext, const HIRect& aRenderRect, void* aData)
|
2009-09-27 14:58:15 -07:00
|
|
|
|
{
|
|
|
|
|
HIThemeTrackDrawInfo* tdi = (HIThemeTrackDrawInfo*)aData;
|
|
|
|
|
HIThemeDrawTrack(tdi, NULL, cgContext, HITHEME_ORIENTATION);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
nsNativeThemeCocoa::DrawScrollbar(CGContextRef aCGContext, const HIRect& aBoxRect, nsIFrame *aFrame)
|
|
|
|
|
{
|
|
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
|
|
|
|
|
HIThemeTrackDrawInfo tdi;
|
2011-09-30 17:20:33 -07:00
|
|
|
|
GetScrollbarDrawInfo(tdi, aFrame, aBoxRect.size, true); // True means we want the press states
|
2009-09-27 14:58:15 -07:00
|
|
|
|
RenderTransformedHIThemeControl(aCGContext, aBoxRect, RenderScrollbar, &tdi);
|
|
|
|
|
|
2008-02-20 17:01:27 -08:00
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
2007-04-10 17:25:11 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nsIFrame*
|
|
|
|
|
nsNativeThemeCocoa::GetParentScrollbarFrame(nsIFrame *aFrame)
|
|
|
|
|
{
|
|
|
|
|
// Walk our parents to find a scrollbar frame
|
|
|
|
|
nsIFrame *scrollbarFrame = aFrame;
|
|
|
|
|
do {
|
2011-10-14 11:11:22 -07:00
|
|
|
|
if (scrollbarFrame->GetType() == nsGkAtoms::scrollbarFrame) break;
|
2007-04-10 17:25:11 -07:00
|
|
|
|
} while ((scrollbarFrame = scrollbarFrame->GetParent()));
|
2013-05-22 02:48:47 -07:00
|
|
|
|
|
2007-04-10 17:25:11 -07:00
|
|
|
|
// We return null if we can't find a parent scrollbar frame
|
|
|
|
|
return scrollbarFrame;
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
|
static bool
|
2009-12-30 07:23:51 -08:00
|
|
|
|
ToolbarCanBeUnified(CGContextRef cgContext, const HIRect& inBoxRect, NSWindow* aWindow)
|
|
|
|
|
{
|
2013-05-22 02:48:47 -07:00
|
|
|
|
if (![aWindow isKindOfClass:[ToolbarWindow class]])
|
2011-09-30 17:20:33 -07:00
|
|
|
|
return false;
|
2010-07-24 02:35:29 -07:00
|
|
|
|
|
2013-05-22 02:48:47 -07:00
|
|
|
|
ToolbarWindow* win = (ToolbarWindow*)aWindow;
|
|
|
|
|
float unifiedToolbarHeight = [win unifiedToolbarHeight];
|
2010-07-24 02:35:29 -07:00
|
|
|
|
return inBoxRect.origin.x == 0 &&
|
2013-05-22 02:48:47 -07:00
|
|
|
|
inBoxRect.size.width >= [win frame].size.width &&
|
2013-05-22 02:50:57 -07:00
|
|
|
|
CGRectGetMaxY(inBoxRect) <= unifiedToolbarHeight;
|
2009-12-30 07:23:51 -08:00
|
|
|
|
}
|
|
|
|
|
|
2013-05-23 07:49:16 -07:00
|
|
|
|
// By default, kCUIWidgetWindowFrame drawing draws rounded corners in the
|
|
|
|
|
// upper corners. Depending on the context type, it fills the background in
|
|
|
|
|
// the corners with black or leaves it transparent. Unfortunately, this corner
|
|
|
|
|
// rounding interacts poorly with the window corner masking we apply during
|
|
|
|
|
// titlebar drawing and results in small remnants of the corner background
|
|
|
|
|
// appearing at the rounded edge.
|
|
|
|
|
// So we draw square corners.
|
|
|
|
|
static void
|
|
|
|
|
DrawNativeTitlebarToolbarWithSquareCorners(CGContextRef aContext, const CGRect& aRect,
|
2014-08-27 17:15:27 -07:00
|
|
|
|
CGFloat aUnifiedHeight, BOOL aIsMain, BOOL aIsFlipped)
|
2008-09-16 01:21:06 -07:00
|
|
|
|
{
|
2013-05-23 07:49:16 -07:00
|
|
|
|
// We extend the draw rect horizontally and clip away the rounded corners.
|
|
|
|
|
const CGFloat extendHorizontal = 10;
|
|
|
|
|
CGRect drawRect = CGRectInset(aRect, -extendHorizontal, 0);
|
2014-08-27 17:15:27 -07:00
|
|
|
|
CGContextSaveGState(aContext);
|
|
|
|
|
CGContextClipToRect(aContext, aRect);
|
|
|
|
|
|
|
|
|
|
RenderWithCoreUI(drawRect, aContext,
|
|
|
|
|
[NSDictionary dictionaryWithObjectsAndKeys:
|
|
|
|
|
@"kCUIWidgetWindowFrame", @"widget",
|
|
|
|
|
@"regularwin", @"windowtype",
|
|
|
|
|
(aIsMain ? @"normal" : @"inactive"), @"state",
|
|
|
|
|
[NSNumber numberWithDouble:aUnifiedHeight], @"kCUIWindowFrameUnifiedTitleBarHeightKey",
|
|
|
|
|
[NSNumber numberWithBool:YES], @"kCUIWindowFrameDrawTitleSeparatorKey",
|
|
|
|
|
[NSNumber numberWithBool:aIsFlipped], @"is.flipped",
|
|
|
|
|
nil]);
|
|
|
|
|
|
|
|
|
|
CGContextRestoreGState(aContext);
|
2013-05-23 07:49:16 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
nsNativeThemeCocoa::DrawUnifiedToolbar(CGContextRef cgContext, const HIRect& inBoxRect,
|
|
|
|
|
NSWindow* aWindow)
|
|
|
|
|
{
|
|
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
|
|
|
|
|
CGContextSaveGState(cgContext);
|
|
|
|
|
CGContextClipToRect(cgContext, inBoxRect);
|
|
|
|
|
|
|
|
|
|
CGFloat unifiedHeight = std::max([(ToolbarWindow*)aWindow unifiedToolbarHeight],
|
|
|
|
|
inBoxRect.size.height);
|
|
|
|
|
BOOL isMain = [aWindow isMainWindow];
|
|
|
|
|
CGFloat titlebarHeight = unifiedHeight - inBoxRect.size.height;
|
|
|
|
|
CGRect drawRect = CGRectMake(inBoxRect.origin.x, inBoxRect.origin.y - titlebarHeight,
|
|
|
|
|
inBoxRect.size.width, inBoxRect.size.height + titlebarHeight);
|
2014-08-27 17:15:27 -07:00
|
|
|
|
DrawNativeTitlebarToolbarWithSquareCorners(cgContext, drawRect, unifiedHeight, isMain, YES);
|
2009-01-06 07:46:59 -08:00
|
|
|
|
|
|
|
|
|
CGContextRestoreGState(cgContext);
|
2011-08-08 07:42:20 -07:00
|
|
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
2009-01-06 07:46:59 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
nsNativeThemeCocoa::DrawStatusBar(CGContextRef cgContext, const HIRect& inBoxRect,
|
|
|
|
|
nsIFrame *aFrame)
|
|
|
|
|
{
|
|
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
|
|
|
|
|
if (inBoxRect.size.height < 2.0f)
|
|
|
|
|
return;
|
|
|
|
|
|
2011-08-08 07:42:20 -07:00
|
|
|
|
CGContextSaveGState(cgContext);
|
|
|
|
|
CGContextClipToRect(cgContext, inBoxRect);
|
2009-01-06 07:46:59 -08:00
|
|
|
|
|
2011-08-08 07:42:20 -07:00
|
|
|
|
// kCUIWidgetWindowFrame draws a complete window frame with both title bar
|
|
|
|
|
// and bottom bar. We only want the bottom bar, so we extend the draw rect
|
|
|
|
|
// upwards to make space for the title bar, and then we clip it away.
|
|
|
|
|
CGRect drawRect = inBoxRect;
|
|
|
|
|
const int extendUpwards = 40;
|
|
|
|
|
drawRect.origin.y -= extendUpwards;
|
|
|
|
|
drawRect.size.height += extendUpwards;
|
2014-08-27 17:15:27 -07:00
|
|
|
|
RenderWithCoreUI(drawRect, cgContext,
|
|
|
|
|
[NSDictionary dictionaryWithObjectsAndKeys:
|
|
|
|
|
@"kCUIWidgetWindowFrame", @"widget",
|
|
|
|
|
@"regularwin", @"windowtype",
|
|
|
|
|
(IsActive(aFrame, YES) ? @"normal" : @"inactive"), @"state",
|
|
|
|
|
[NSNumber numberWithInt:inBoxRect.size.height], @"kCUIWindowFrameBottomBarHeightKey",
|
|
|
|
|
[NSNumber numberWithBool:YES], @"kCUIWindowFrameDrawBottomBarSeparatorKey",
|
|
|
|
|
[NSNumber numberWithBool:YES], @"is.flipped",
|
|
|
|
|
nil]);
|
2011-08-08 07:42:20 -07:00
|
|
|
|
|
|
|
|
|
CGContextRestoreGState(cgContext);
|
2009-01-06 07:46:59 -08:00
|
|
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-22 02:48:47 -07:00
|
|
|
|
void
|
|
|
|
|
nsNativeThemeCocoa::DrawNativeTitlebar(CGContextRef aContext, CGRect aTitlebarRect,
|
2014-08-27 17:15:27 -07:00
|
|
|
|
CGFloat aUnifiedHeight, BOOL aIsMain, BOOL aIsFlipped)
|
2013-05-22 02:48:47 -07:00
|
|
|
|
{
|
2013-05-23 07:49:16 -07:00
|
|
|
|
CGFloat unifiedHeight = std::max(aUnifiedHeight, aTitlebarRect.size.height);
|
2014-08-27 17:15:27 -07:00
|
|
|
|
DrawNativeTitlebarToolbarWithSquareCorners(aContext, aTitlebarRect, unifiedHeight, aIsMain, aIsFlipped);
|
2013-05-22 02:48:47 -07:00
|
|
|
|
}
|
|
|
|
|
|
2009-09-27 14:58:58 -07:00
|
|
|
|
static void
|
2009-11-13 14:56:30 -08:00
|
|
|
|
RenderResizer(CGContextRef cgContext, const HIRect& aRenderRect, void* aData)
|
2009-09-27 14:58:58 -07:00
|
|
|
|
{
|
|
|
|
|
HIThemeGrowBoxDrawInfo* drawInfo = (HIThemeGrowBoxDrawInfo*)aData;
|
|
|
|
|
HIThemeDrawGrowBox(&CGPointZero, drawInfo, cgContext, kHIThemeOrientationNormal);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
nsNativeThemeCocoa::DrawResizer(CGContextRef cgContext, const HIRect& aRect,
|
|
|
|
|
nsIFrame *aFrame)
|
|
|
|
|
{
|
|
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
|
|
|
|
|
HIThemeGrowBoxDrawInfo drawInfo;
|
|
|
|
|
drawInfo.version = 0;
|
|
|
|
|
drawInfo.state = kThemeStateActive;
|
|
|
|
|
drawInfo.kind = kHIThemeGrowBoxKindNormal;
|
|
|
|
|
drawInfo.direction = kThemeGrowRight | kThemeGrowDown;
|
|
|
|
|
drawInfo.size = kHIThemeGrowBoxSizeNormal;
|
|
|
|
|
|
|
|
|
|
RenderTransformedHIThemeControl(cgContext, aRect, RenderResizer, &drawInfo,
|
|
|
|
|
IsFrameRTL(aFrame));
|
|
|
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-28 06:22:16 -07:00
|
|
|
|
static bool
|
|
|
|
|
ScrollbarTrackAndThumbDrawSeparately()
|
|
|
|
|
{
|
|
|
|
|
return nsLookAndFeel::UseOverlayScrollbars() || nsCocoaFeatures::OnLionOrLater();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
nsNativeThemeCocoa::IsParentScrollbarRolledOver(nsIFrame* aFrame)
|
|
|
|
|
{
|
|
|
|
|
nsIFrame* scrollbarFrame = GetParentScrollbarFrame(aFrame);
|
|
|
|
|
return nsLookAndFeel::UseOverlayScrollbars()
|
|
|
|
|
? CheckBooleanAttr(scrollbarFrame, nsGkAtoms::hover)
|
|
|
|
|
: GetContentState(scrollbarFrame, NS_THEME_NONE).HasState(NS_EVENT_STATE_HOVER);
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-13 09:45:57 -07:00
|
|
|
|
static bool
|
2014-06-19 23:42:30 -07:00
|
|
|
|
IsHiDPIContext(nsPresContext* aContext)
|
2012-08-13 09:45:57 -07:00
|
|
|
|
{
|
2012-10-13 05:10:54 -07:00
|
|
|
|
return nsPresContext::AppUnitsPerCSSPixel() >=
|
2014-06-19 23:42:30 -07:00
|
|
|
|
2 * aContext->DeviceContext()->UnscaledAppUnitsPerDevPixel();
|
2012-08-13 09:45:57 -07:00
|
|
|
|
}
|
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
|
NS_IMETHODIMP
|
2011-04-07 18:04:40 -07:00
|
|
|
|
nsNativeThemeCocoa::DrawWidgetBackground(nsRenderingContext* aContext,
|
|
|
|
|
nsIFrame* aFrame,
|
2012-08-22 08:56:38 -07:00
|
|
|
|
uint8_t aWidgetType,
|
2011-04-07 18:04:40 -07:00
|
|
|
|
const nsRect& aRect,
|
2014-03-17 01:42:48 -07:00
|
|
|
|
const nsRect& aDirtyRect)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
{
|
2008-02-20 17:01:27 -08:00
|
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
|
// setup to draw into the correct port
|
2014-06-19 23:42:30 -07:00
|
|
|
|
int32_t p2a = aFrame->PresContext()->AppUnitsPerDevPixel();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
2011-04-07 18:04:40 -07:00
|
|
|
|
gfxRect nativeDirtyRect(aDirtyRect.x, aDirtyRect.y,
|
|
|
|
|
aDirtyRect.width, aDirtyRect.height);
|
2008-02-20 03:33:27 -08:00
|
|
|
|
gfxRect nativeWidgetRect(aRect.x, aRect.y, aRect.width, aRect.height);
|
|
|
|
|
nativeWidgetRect.ScaleInverse(gfxFloat(p2a));
|
2008-07-24 16:01:59 -07:00
|
|
|
|
nativeDirtyRect.ScaleInverse(gfxFloat(p2a));
|
2008-07-27 09:08:51 -07:00
|
|
|
|
nativeWidgetRect.Round();
|
2008-10-22 09:39:08 -07:00
|
|
|
|
if (nativeWidgetRect.IsEmpty())
|
|
|
|
|
return NS_OK; // Don't attempt to draw invisible widgets.
|
2008-02-20 03:33:27 -08:00
|
|
|
|
|
2011-04-07 18:04:40 -07:00
|
|
|
|
gfxContext* thebesCtx = aContext->ThebesContext();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
if (!thebesCtx)
|
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
2012-08-13 09:45:57 -07:00
|
|
|
|
gfxContextMatrixAutoSaveRestore save(thebesCtx);
|
|
|
|
|
|
2014-06-19 23:42:30 -07:00
|
|
|
|
bool hidpi = IsHiDPIContext(aFrame->PresContext());
|
2012-10-29 02:22:30 -07:00
|
|
|
|
if (hidpi) {
|
2012-08-13 09:45:57 -07:00
|
|
|
|
// Use high-resolution drawing.
|
|
|
|
|
nativeWidgetRect.ScaleInverse(2.0f);
|
|
|
|
|
nativeDirtyRect.ScaleInverse(2.0f);
|
2014-09-10 23:57:38 -07:00
|
|
|
|
thebesCtx->SetMatrix(
|
|
|
|
|
thebesCtx->CurrentMatrix().Scale(2.0f, 2.0f));
|
2012-08-13 09:45:57 -07:00
|
|
|
|
}
|
|
|
|
|
|
2014-08-28 20:08:15 -07:00
|
|
|
|
gfxQuartzNativeDrawing nativeDrawing(thebesCtx, nativeDirtyRect);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
2008-02-20 03:33:27 -08:00
|
|
|
|
CGContextRef cgContext = nativeDrawing.BeginNativeDrawing();
|
2012-07-30 07:20:58 -07:00
|
|
|
|
if (cgContext == nullptr) {
|
2008-01-25 16:26:48 -08:00
|
|
|
|
// The Quartz surface handles 0x0 surfaces by internally
|
|
|
|
|
// making all operations no-ops; there's no cgcontext created for them.
|
|
|
|
|
// Unfortunately, this means that callers that want to render
|
|
|
|
|
// directly to the CGContext need to be aware of this quirk.
|
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
}
|
|
|
|
|
|
2014-09-18 01:52:35 -07:00
|
|
|
|
if (hidpi) {
|
|
|
|
|
// Set the context's "base transform" to in order to get correctly-sized focus rings.
|
|
|
|
|
CGContextSetBaseCTM(cgContext, CGAffineTransformMakeScale(2, 2));
|
|
|
|
|
}
|
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
|
#if 0
|
|
|
|
|
if (1 /*aWidgetType == NS_THEME_TEXTFIELD*/) {
|
|
|
|
|
fprintf(stderr, "Native theme drawing widget %d [%p] dis:%d in rect [%d %d %d %d]\n",
|
|
|
|
|
aWidgetType, aFrame, IsDisabled(aFrame), aRect.x, aRect.y, aRect.width, aRect.height);
|
2007-09-28 23:12:39 -07:00
|
|
|
|
fprintf(stderr, "Cairo matrix: [%f %f %f %f %f %f]\n",
|
2014-06-17 10:35:51 -07:00
|
|
|
|
mat._11, mat._12, mat._21, mat._22, mat._31, mat._32);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
fprintf(stderr, "Native theme xform[0]: [%f %f %f %f %f %f]\n",
|
|
|
|
|
mm0.a, mm0.b, mm0.c, mm0.d, mm0.tx, mm0.ty);
|
|
|
|
|
CGAffineTransform mm = CGContextGetCTM(cgContext);
|
|
|
|
|
fprintf(stderr, "Native theme xform[1]: [%f %f %f %f %f %f]\n",
|
|
|
|
|
mm.a, mm.b, mm.c, mm.d, mm.tx, mm.ty);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2008-07-27 09:08:51 -07:00
|
|
|
|
CGRect macRect = CGRectMake(nativeWidgetRect.X(), nativeWidgetRect.Y(),
|
|
|
|
|
nativeWidgetRect.Width(), nativeWidgetRect.Height());
|
2007-08-07 12:36:40 -07:00
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
|
#if 0
|
|
|
|
|
fprintf(stderr, " --> macRect %f %f %f %f\n",
|
|
|
|
|
macRect.origin.x, macRect.origin.y, macRect.size.width, macRect.size.height);
|
|
|
|
|
CGRect bounds = CGContextGetClipBoundingBox(cgContext);
|
|
|
|
|
fprintf(stderr, " --> clip bounds: %f %f %f %f\n",
|
|
|
|
|
bounds.origin.x, bounds.origin.y, bounds.size.width, bounds.size.height);
|
|
|
|
|
|
|
|
|
|
//CGContextSetRGBFillColor(cgContext, 0.0, 0.0, 1.0, 0.1);
|
|
|
|
|
//CGContextFillRect(cgContext, bounds);
|
|
|
|
|
#endif
|
|
|
|
|
|
2014-04-02 21:18:36 -07:00
|
|
|
|
EventStates eventState = GetContentState(aFrame, aWidgetType);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
|
|
switch (aWidgetType) {
|
|
|
|
|
case NS_THEME_DIALOG: {
|
2014-04-02 08:03:08 -07:00
|
|
|
|
HIThemeSetFill(kThemeBrushDialogBackgroundActive, NULL, cgContext, HITHEME_ORIENTATION);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
CGContextFillRect(cgContext, macRect);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case NS_THEME_MENUPOPUP: {
|
2012-02-21 17:44:40 -08:00
|
|
|
|
HIThemeMenuDrawInfo mdi;
|
|
|
|
|
memset(&mdi, 0, sizeof(mdi));
|
|
|
|
|
mdi.version = 0;
|
|
|
|
|
mdi.menuType = IsDisabled(aFrame, eventState) ?
|
|
|
|
|
static_cast<ThemeMenuType>(kThemeMenuTypeInactive) :
|
|
|
|
|
static_cast<ThemeMenuType>(kThemeMenuTypePopUp);
|
2009-01-12 11:23:51 -08:00
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
|
bool isLeftOfParent = false;
|
2009-01-12 11:23:51 -08:00
|
|
|
|
if (IsSubmenu(aFrame, &isLeftOfParent) && !isLeftOfParent) {
|
|
|
|
|
mdi.menuType = kThemeMenuTypeHierarchical;
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-11 06:37:38 -08:00
|
|
|
|
// The rounded corners draw outside the frame.
|
|
|
|
|
CGRect deflatedRect = CGRectMake(macRect.origin.x, macRect.origin.y + 4,
|
|
|
|
|
macRect.size.width, macRect.size.height - 8);
|
|
|
|
|
HIThemeDrawMenuBackground(&deflatedRect, &mdi, cgContext, HITHEME_ORIENTATION);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
2014-09-08 02:45:00 -07:00
|
|
|
|
case NS_THEME_MENUARROW: {
|
|
|
|
|
bool isRTL = IsFrameRTL(aFrame);
|
|
|
|
|
DrawMenuIcon(cgContext, macRect, eventState, aFrame, kMenuarrowSize,
|
|
|
|
|
isRTL ? kMenuarrowLeftImage : kMenuarrowRightImage, true);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
2014-07-04 11:02:44 -07:00
|
|
|
|
case NS_THEME_MENUITEM:
|
|
|
|
|
case NS_THEME_CHECKMENUITEM: {
|
2014-07-10 02:58:08 -07:00
|
|
|
|
SurfaceFormat format = thebesCtx->GetDrawTarget()->GetFormat();
|
|
|
|
|
bool isTransparent = (format == SurfaceFormat::R8G8B8A8) ||
|
2014-09-08 02:45:00 -07:00
|
|
|
|
(format == SurfaceFormat::B8G8R8A8);
|
2013-07-12 14:19:28 -07:00
|
|
|
|
if (isTransparent) {
|
2012-03-09 07:17:37 -08:00
|
|
|
|
// Clear the background to get correct transparency.
|
|
|
|
|
CGContextClearRect(cgContext, macRect);
|
|
|
|
|
}
|
2008-12-15 12:27:30 -08:00
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
|
// maybe use kThemeMenuItemHierBackground or PopUpBackground instead of just Plain?
|
2012-02-21 17:44:40 -08:00
|
|
|
|
HIThemeMenuItemDrawInfo drawInfo;
|
|
|
|
|
memset(&drawInfo, 0, sizeof(drawInfo));
|
|
|
|
|
drawInfo.version = 0;
|
|
|
|
|
drawInfo.itemType = kThemeMenuItemPlain;
|
|
|
|
|
drawInfo.state = (IsDisabled(aFrame, eventState) ?
|
|
|
|
|
static_cast<ThemeMenuState>(kThemeMenuDisabled) :
|
|
|
|
|
CheckBooleanAttr(aFrame, nsGkAtoms::menuactive) ?
|
|
|
|
|
static_cast<ThemeMenuState>(kThemeMenuSelected) :
|
|
|
|
|
static_cast<ThemeMenuState>(kThemeMenuActive));
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
|
|
// XXX pass in the menu rect instead of always using the item rect
|
|
|
|
|
HIRect ignored;
|
|
|
|
|
HIThemeDrawMenuItem(&macRect, &macRect, &drawInfo, cgContext, HITHEME_ORIENTATION, &ignored);
|
2014-07-04 11:02:44 -07:00
|
|
|
|
|
|
|
|
|
if (aWidgetType == NS_THEME_CHECKMENUITEM) {
|
2014-09-08 02:45:00 -07:00
|
|
|
|
DrawMenuIcon(cgContext, macRect, eventState, aFrame, kCheckmarkSize, kCheckmarkImage, false);
|
2014-07-04 11:02:44 -07:00
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
2008-02-24 05:41:22 -08:00
|
|
|
|
case NS_THEME_MENUSEPARATOR: {
|
|
|
|
|
ThemeMenuState menuState;
|
2010-09-27 18:25:18 -07:00
|
|
|
|
if (IsDisabled(aFrame, eventState)) {
|
2008-02-24 05:41:22 -08:00
|
|
|
|
menuState = kThemeMenuDisabled;
|
|
|
|
|
}
|
|
|
|
|
else {
|
2011-10-14 11:11:22 -07:00
|
|
|
|
menuState = CheckBooleanAttr(aFrame, nsGkAtoms::menuactive) ?
|
2008-02-24 05:41:22 -08:00
|
|
|
|
kThemeMenuSelected : kThemeMenuActive;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
HIThemeMenuItemDrawInfo midi = { 0, kThemeMenuItemPlain, menuState };
|
|
|
|
|
HIThemeDrawMenuSeparator(&macRect, &macRect, &midi, cgContext, HITHEME_ORIENTATION);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
2014-09-08 02:45:00 -07:00
|
|
|
|
case NS_THEME_BUTTON_ARROW_UP:
|
|
|
|
|
case NS_THEME_BUTTON_ARROW_DOWN:
|
|
|
|
|
DrawMenuIcon(cgContext, macRect, eventState, aFrame, kMenuScrollArrowSize,
|
|
|
|
|
aWidgetType == NS_THEME_BUTTON_ARROW_UP ?
|
|
|
|
|
kMenuUpScrollArrowImage : kMenuDownScrollArrowImage, true);
|
|
|
|
|
break;
|
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
|
case NS_THEME_TOOLTIP:
|
2014-10-01 09:24:58 -07:00
|
|
|
|
if (nsCocoaFeatures::OnYosemiteOrLater()) {
|
|
|
|
|
CGContextSetRGBFillColor(cgContext, 0.945, 0.942, 0.945, 0.950);
|
|
|
|
|
} else {
|
|
|
|
|
CGContextSetRGBFillColor(cgContext, 0.996, 1.000, 0.792, 0.950);
|
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
CGContextFillRect(cgContext, macRect);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case NS_THEME_CHECKBOX:
|
2008-11-03 05:12:59 -08:00
|
|
|
|
case NS_THEME_RADIO: {
|
2011-09-28 23:19:26 -07:00
|
|
|
|
bool isCheckbox = (aWidgetType == NS_THEME_CHECKBOX);
|
2008-10-13 09:58:40 -07:00
|
|
|
|
DrawCheckboxOrRadio(cgContext, isCheckbox, macRect, GetCheckedOrSelected(aFrame, !isCheckbox),
|
2010-09-19 18:16:49 -07:00
|
|
|
|
eventState, aFrame);
|
2008-10-13 09:58:40 -07:00
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case NS_THEME_BUTTON:
|
2009-01-18 03:05:38 -08:00
|
|
|
|
if (IsDefaultButton(aFrame)) {
|
2013-03-07 14:26:39 -08:00
|
|
|
|
if (!IsDisabled(aFrame, eventState) && FrameIsInActiveWindow(aFrame) &&
|
|
|
|
|
!QueueAnimatedContentForRefresh(aFrame->GetContent(), 10)) {
|
2010-11-13 00:19:38 -08:00
|
|
|
|
NS_WARNING("Unable to animate button!");
|
|
|
|
|
}
|
2010-09-19 18:16:49 -07:00
|
|
|
|
DrawButton(cgContext, kThemePushButton, macRect, true,
|
2009-01-18 03:05:38 -08:00
|
|
|
|
kThemeButtonOff, kThemeAdornmentNone, eventState, aFrame);
|
2009-08-10 14:23:50 -07:00
|
|
|
|
} else if (IsButtonTypeMenu(aFrame)) {
|
|
|
|
|
DrawDropdown(cgContext, macRect, eventState, aWidgetType, aFrame);
|
2009-01-18 03:05:38 -08:00
|
|
|
|
} else {
|
2014-02-27 09:12:16 -08:00
|
|
|
|
DrawPushButton(cgContext, macRect, eventState, aWidgetType, aFrame);
|
2009-01-18 03:05:38 -08:00
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
break;
|
|
|
|
|
|
2014-06-14 05:48:08 -07:00
|
|
|
|
case NS_THEME_FOCUS_OUTLINE:
|
|
|
|
|
DrawFocusOutline(cgContext, macRect, eventState, aWidgetType, aFrame);
|
|
|
|
|
break;
|
|
|
|
|
|
2014-02-27 09:12:16 -08:00
|
|
|
|
case NS_THEME_MOZ_MAC_HELP_BUTTON:
|
|
|
|
|
DrawPushButton(cgContext, macRect, eventState, aWidgetType, aFrame);
|
|
|
|
|
break;
|
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
|
case NS_THEME_BUTTON_BEVEL:
|
|
|
|
|
DrawButton(cgContext, kThemeMediumBevelButton, macRect,
|
2010-09-19 18:16:49 -07:00
|
|
|
|
IsDefaultButton(aFrame), kThemeButtonOff, kThemeAdornmentNone,
|
|
|
|
|
eventState, aFrame);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case NS_THEME_SPINNER: {
|
2013-12-05 10:00:23 -08:00
|
|
|
|
nsIContent* content = aFrame->GetContent();
|
2013-12-05 08:20:34 -08:00
|
|
|
|
if (content->IsHTML()) {
|
|
|
|
|
// In HTML the theming for the spin buttons is drawn individually into
|
|
|
|
|
// their own backgrounds instead of being drawn into the background of
|
|
|
|
|
// their spinner parent as it is for XUL.
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
ThemeDrawState state = kThemeStateActive;
|
2011-10-14 11:11:22 -07:00
|
|
|
|
if (content->AttrValueIs(kNameSpaceID_None, nsGkAtoms::state,
|
2007-03-22 10:30:00 -07:00
|
|
|
|
NS_LITERAL_STRING("up"), eCaseMatters)) {
|
|
|
|
|
state = kThemeStatePressedUp;
|
|
|
|
|
}
|
2011-10-14 11:11:22 -07:00
|
|
|
|
else if (content->AttrValueIs(kNameSpaceID_None, nsGkAtoms::state,
|
2007-03-22 10:30:00 -07:00
|
|
|
|
NS_LITERAL_STRING("down"), eCaseMatters)) {
|
|
|
|
|
state = kThemeStatePressedDown;
|
|
|
|
|
}
|
|
|
|
|
|
2010-09-19 18:16:49 -07:00
|
|
|
|
DrawSpinButtons(cgContext, kThemeIncDecButton, macRect, state,
|
|
|
|
|
kThemeAdornmentNone, eventState, aFrame);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
2013-12-05 08:20:34 -08:00
|
|
|
|
case NS_THEME_SPINNER_UP_BUTTON:
|
|
|
|
|
case NS_THEME_SPINNER_DOWN_BUTTON: {
|
|
|
|
|
nsNumberControlFrame* numberControlFrame =
|
|
|
|
|
nsNumberControlFrame::GetNumberControlFrameForSpinButton(aFrame);
|
|
|
|
|
if (numberControlFrame) {
|
|
|
|
|
ThemeDrawState state = kThemeStateActive;
|
|
|
|
|
if (numberControlFrame->SpinnerUpButtonIsDepressed()) {
|
|
|
|
|
state = kThemeStatePressedUp;
|
|
|
|
|
} else if (numberControlFrame->SpinnerDownButtonIsDepressed()) {
|
|
|
|
|
state = kThemeStatePressedDown;
|
|
|
|
|
}
|
|
|
|
|
DrawSpinButton(cgContext, kThemeIncDecButtonMini, macRect, state,
|
|
|
|
|
kThemeAdornmentNone, eventState, aFrame, aWidgetType);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
|
case NS_THEME_TOOLBAR_BUTTON:
|
2011-08-08 07:42:45 -07:00
|
|
|
|
DrawSegment(cgContext, macRect, eventState, aFrame, toolbarButtonRenderSettings);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case NS_THEME_TOOLBAR_SEPARATOR: {
|
|
|
|
|
HIThemeSeparatorDrawInfo sdi = { 0, kThemeStateActive };
|
|
|
|
|
HIThemeDrawSeparator(&macRect, &sdi, cgContext, HITHEME_ORIENTATION);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
2008-09-16 01:21:06 -07:00
|
|
|
|
case NS_THEME_MOZ_MAC_UNIFIED_TOOLBAR:
|
2008-12-11 06:48:13 -08:00
|
|
|
|
case NS_THEME_TOOLBAR: {
|
2009-12-30 07:23:51 -08:00
|
|
|
|
NSWindow* win = NativeWindowForFrame(aFrame);
|
|
|
|
|
if (ToolbarCanBeUnified(cgContext, macRect, win)) {
|
|
|
|
|
DrawUnifiedToolbar(cgContext, macRect, win);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2012-08-20 03:00:49 -07:00
|
|
|
|
BOOL isMain = [win isMainWindow];
|
2009-08-03 15:27:31 -07:00
|
|
|
|
CGRect drawRect = macRect;
|
2008-12-11 06:48:13 -08:00
|
|
|
|
|
|
|
|
|
// top border
|
2009-08-03 15:27:31 -07:00
|
|
|
|
drawRect.size.height = 1.0f;
|
|
|
|
|
DrawNativeGreyColorInRect(cgContext, toolbarTopBorderGrey, drawRect, isMain);
|
2008-12-11 06:48:13 -08:00
|
|
|
|
|
|
|
|
|
// background
|
2009-08-03 15:27:31 -07:00
|
|
|
|
drawRect.origin.y += drawRect.size.height;
|
|
|
|
|
drawRect.size.height = macRect.size.height - 2.0f;
|
2011-08-08 07:42:20 -07:00
|
|
|
|
DrawNativeGreyColorInRect(cgContext, toolbarFillGrey, drawRect, isMain);
|
2008-12-11 06:48:13 -08:00
|
|
|
|
|
|
|
|
|
// bottom border
|
2009-08-03 15:27:31 -07:00
|
|
|
|
drawRect.origin.y += drawRect.size.height;
|
|
|
|
|
drawRect.size.height = 1.0f;
|
2011-08-08 07:42:20 -07:00
|
|
|
|
DrawNativeGreyColorInRect(cgContext, toolbarBottomBorderGrey, drawRect, isMain);
|
2008-12-11 06:48:13 -08:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
2013-05-22 02:48:47 -07:00
|
|
|
|
case NS_THEME_WINDOW_TITLEBAR: {
|
|
|
|
|
NSWindow* win = NativeWindowForFrame(aFrame);
|
|
|
|
|
BOOL isMain = [win isMainWindow];
|
2013-11-05 17:22:00 -08:00
|
|
|
|
float unifiedToolbarHeight = [win isKindOfClass:[ToolbarWindow class]] ?
|
|
|
|
|
[(ToolbarWindow*)win unifiedToolbarHeight] : macRect.size.height;
|
2014-08-27 17:15:27 -07:00
|
|
|
|
DrawNativeTitlebar(cgContext, macRect, unifiedToolbarHeight, isMain, YES);
|
2013-05-22 02:48:47 -07:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
2009-01-06 07:46:59 -08:00
|
|
|
|
case NS_THEME_TOOLBOX: {
|
2007-03-22 10:30:00 -07:00
|
|
|
|
HIThemeHeaderDrawInfo hdi = { 0, kThemeStateActive, kHIThemeHeaderKindWindow };
|
|
|
|
|
HIThemeDrawHeader(&macRect, &hdi, cgContext, HITHEME_ORIENTATION);
|
|
|
|
|
}
|
|
|
|
|
break;
|
2009-01-06 07:46:59 -08:00
|
|
|
|
|
|
|
|
|
case NS_THEME_STATUSBAR:
|
|
|
|
|
DrawStatusBar(cgContext, macRect, aFrame);
|
|
|
|
|
break;
|
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
|
case NS_THEME_DROPDOWN:
|
2009-02-11 07:54:10 -08:00
|
|
|
|
case NS_THEME_DROPDOWN_TEXTFIELD:
|
2009-08-10 14:23:50 -07:00
|
|
|
|
DrawDropdown(cgContext, macRect, eventState, aWidgetType, aFrame);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case NS_THEME_DROPDOWN_BUTTON:
|
2011-09-30 17:20:33 -07:00
|
|
|
|
DrawButton(cgContext, kThemeArrowButton, macRect, false, kThemeButtonOn,
|
2008-09-22 01:57:42 -07:00
|
|
|
|
kThemeAdornmentArrowDownArrow, eventState, aFrame);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
break;
|
|
|
|
|
|
2008-03-13 13:24:29 -07:00
|
|
|
|
case NS_THEME_GROUPBOX: {
|
|
|
|
|
HIThemeGroupBoxDrawInfo gdi = { 0, kThemeStateActive, kHIThemeGroupBoxKindPrimary };
|
|
|
|
|
HIThemeDrawGroupBox(&macRect, &gdi, cgContext, HITHEME_ORIENTATION);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
|
case NS_THEME_TEXTFIELD:
|
2013-12-08 15:23:28 -08:00
|
|
|
|
case NS_THEME_NUMBER_INPUT:
|
2007-03-22 10:30:00 -07:00
|
|
|
|
// HIThemeSetFill is not available on 10.3
|
|
|
|
|
CGContextSetRGBFillColor(cgContext, 1.0, 1.0, 1.0, 1.0);
|
|
|
|
|
CGContextFillRect(cgContext, macRect);
|
2008-02-07 13:54:24 -08:00
|
|
|
|
|
|
|
|
|
// XUL textboxes set the native appearance on the containing box, while
|
|
|
|
|
// concrete focus is set on the html:input element within it. We can
|
|
|
|
|
// though, check the focused attribute of xul textboxes in this case.
|
2010-04-21 07:53:42 -07:00
|
|
|
|
// On Mac, focus rings are always shown for textboxes, so we do not need
|
|
|
|
|
// to check the window's focus ring state here
|
2009-08-24 13:02:07 -07:00
|
|
|
|
if (aFrame->GetContent()->IsXUL() && IsFocused(aFrame)) {
|
2008-02-07 13:54:24 -08:00
|
|
|
|
eventState |= NS_EVENT_STATE_FOCUS;
|
|
|
|
|
}
|
|
|
|
|
|
2010-09-27 18:25:18 -07:00
|
|
|
|
DrawFrame(cgContext, kHIThemeFrameTextFieldSquare, macRect,
|
|
|
|
|
IsDisabled(aFrame, eventState) || IsReadOnly(aFrame), eventState);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
break;
|
|
|
|
|
|
2008-12-06 03:40:58 -08:00
|
|
|
|
case NS_THEME_SEARCHFIELD:
|
2010-09-19 18:16:49 -07:00
|
|
|
|
DrawSearchField(cgContext, macRect, aFrame, eventState);
|
2008-12-06 03:40:58 -08:00
|
|
|
|
break;
|
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
|
case NS_THEME_PROGRESSBAR:
|
2014-05-13 13:04:42 -07:00
|
|
|
|
{
|
|
|
|
|
double value = GetProgressValue(aFrame);
|
|
|
|
|
double maxValue = GetProgressMaxValue(aFrame);
|
|
|
|
|
// Don't request repaints for scrollbars at 100% because those don't animate.
|
|
|
|
|
if (value < maxValue) {
|
|
|
|
|
if (!QueueAnimatedContentForRefresh(aFrame->GetContent(), 30)) {
|
|
|
|
|
NS_WARNING("Unable to animate progressbar!");
|
|
|
|
|
}
|
2010-11-13 00:19:38 -08:00
|
|
|
|
}
|
2011-02-28 18:06:22 -08:00
|
|
|
|
DrawProgress(cgContext, macRect, IsIndeterminateProgress(aFrame, eventState),
|
2013-02-16 13:51:02 -08:00
|
|
|
|
aFrame->StyleDisplay()->mOrient != NS_STYLE_ORIENT_VERTICAL,
|
2014-05-13 13:04:42 -07:00
|
|
|
|
value, maxValue, aFrame);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
break;
|
2014-05-13 13:04:42 -07:00
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
|
|
case NS_THEME_PROGRESSBAR_VERTICAL:
|
2011-02-28 18:06:22 -08:00
|
|
|
|
DrawProgress(cgContext, macRect, IsIndeterminateProgress(aFrame, eventState),
|
2011-09-30 17:20:33 -07:00
|
|
|
|
false, GetProgressValue(aFrame),
|
2008-10-30 02:34:23 -07:00
|
|
|
|
GetProgressMaxValue(aFrame), aFrame);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
break;
|
|
|
|
|
|
2012-06-06 00:56:28 -07:00
|
|
|
|
case NS_THEME_METERBAR:
|
|
|
|
|
DrawMeter(cgContext, macRect, aFrame);
|
|
|
|
|
break;
|
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
|
case NS_THEME_PROGRESSBAR_CHUNK:
|
|
|
|
|
case NS_THEME_PROGRESSBAR_CHUNK_VERTICAL:
|
2012-06-06 00:56:28 -07:00
|
|
|
|
case NS_THEME_METERBAR_CHUNK:
|
|
|
|
|
// Do nothing: progress and meter bars cases will draw chunks.
|
2007-03-22 10:30:00 -07:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case NS_THEME_TREEVIEW_TWISTY:
|
2011-09-30 17:20:33 -07:00
|
|
|
|
DrawButton(cgContext, kThemeDisclosureButton, macRect, false,
|
2008-09-22 01:57:42 -07:00
|
|
|
|
kThemeDisclosureRight, kThemeAdornmentNone, eventState, aFrame);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case NS_THEME_TREEVIEW_TWISTY_OPEN:
|
2011-09-30 17:20:33 -07:00
|
|
|
|
DrawButton(cgContext, kThemeDisclosureButton, macRect, false,
|
2008-09-22 01:57:42 -07:00
|
|
|
|
kThemeDisclosureDown, kThemeAdornmentNone, eventState, aFrame);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case NS_THEME_TREEVIEW_HEADER_CELL: {
|
|
|
|
|
TreeSortDirection sortDirection = GetTreeSortDirection(aFrame);
|
2011-09-30 17:20:33 -07:00
|
|
|
|
DrawButton(cgContext, kThemeListHeaderButton, macRect, false,
|
2007-03-22 10:30:00 -07:00
|
|
|
|
sortDirection == eTreeSortDirection_Natural ? kThemeButtonOff : kThemeButtonOn,
|
2008-11-27 14:14:54 -08:00
|
|
|
|
sortDirection == eTreeSortDirection_Ascending ?
|
2010-09-19 18:16:49 -07:00
|
|
|
|
kThemeAdornmentHeaderButtonSortUp : kThemeAdornmentNone, eventState, aFrame);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case NS_THEME_TREEVIEW_TREEITEM:
|
|
|
|
|
case NS_THEME_TREEVIEW:
|
|
|
|
|
// HIThemeSetFill is not available on 10.3
|
|
|
|
|
// HIThemeSetFill(kThemeBrushWhite, NULL, cgContext, HITHEME_ORIENTATION);
|
|
|
|
|
CGContextSetRGBFillColor(cgContext, 1.0, 1.0, 1.0, 1.0);
|
|
|
|
|
CGContextFillRect(cgContext, macRect);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case NS_THEME_TREEVIEW_HEADER:
|
|
|
|
|
// do nothing, taken care of by individual header cells
|
|
|
|
|
case NS_THEME_TREEVIEW_HEADER_SORTARROW:
|
|
|
|
|
// do nothing, taken care of by treeview header
|
|
|
|
|
case NS_THEME_TREEVIEW_LINE:
|
|
|
|
|
// do nothing, these lines don't exist on macos
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case NS_THEME_SCALE_HORIZONTAL:
|
|
|
|
|
case NS_THEME_SCALE_VERTICAL: {
|
2012-08-22 08:56:38 -07:00
|
|
|
|
int32_t curpos = CheckIntAttr(aFrame, nsGkAtoms::curpos, 0);
|
|
|
|
|
int32_t minpos = CheckIntAttr(aFrame, nsGkAtoms::minpos, 0);
|
|
|
|
|
int32_t maxpos = CheckIntAttr(aFrame, nsGkAtoms::maxpos, 100);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
if (!maxpos)
|
|
|
|
|
maxpos = 100;
|
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
|
bool reverse = aFrame->GetContent()->
|
2011-10-14 11:11:22 -07:00
|
|
|
|
AttrValueIs(kNameSpaceID_None, nsGkAtoms::dir,
|
2007-04-09 15:39:57 -07:00
|
|
|
|
NS_LITERAL_STRING("reverse"), eCaseMatters);
|
2010-09-19 18:16:49 -07:00
|
|
|
|
DrawScale(cgContext, macRect, eventState,
|
2007-04-09 15:39:57 -07:00
|
|
|
|
(aWidgetType == NS_THEME_SCALE_VERTICAL), reverse,
|
2008-09-22 01:57:42 -07:00
|
|
|
|
curpos, minpos, maxpos, aFrame);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case NS_THEME_SCALE_THUMB_HORIZONTAL:
|
|
|
|
|
case NS_THEME_SCALE_THUMB_VERTICAL:
|
|
|
|
|
// do nothing, drawn by scale
|
|
|
|
|
break;
|
|
|
|
|
|
2013-03-15 22:40:15 -07:00
|
|
|
|
case NS_THEME_RANGE: {
|
|
|
|
|
nsRangeFrame *rangeFrame = do_QueryFrame(aFrame);
|
|
|
|
|
if (!rangeFrame) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
2013-04-16 16:50:26 -07:00
|
|
|
|
// DrawScale requires integer min, max and value. This is purely for
|
|
|
|
|
// drawing, so we normalize to a range 0-1000 here.
|
|
|
|
|
int32_t value = int32_t(rangeFrame->GetValueAsFractionOfRange() * 1000);
|
|
|
|
|
int32_t min = 0;
|
|
|
|
|
int32_t max = 1000;
|
2013-03-29 03:42:49 -07:00
|
|
|
|
bool isVertical = !IsRangeHorizontal(aFrame);
|
2013-03-15 22:40:15 -07:00
|
|
|
|
bool reverseDir =
|
2013-03-29 03:42:49 -07:00
|
|
|
|
isVertical ||
|
2013-03-15 22:40:15 -07:00
|
|
|
|
rangeFrame->StyleVisibility()->mDirection == NS_STYLE_DIRECTION_RTL;
|
|
|
|
|
DrawScale(cgContext, macRect, eventState, isVertical, reverseDir,
|
|
|
|
|
value, min, max, aFrame);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2007-04-10 17:25:11 -07:00
|
|
|
|
case NS_THEME_SCROLLBAR_SMALL:
|
2013-05-02 07:58:00 -07:00
|
|
|
|
case NS_THEME_SCROLLBAR:
|
2014-05-28 06:22:16 -07:00
|
|
|
|
if (!ScrollbarTrackAndThumbDrawSeparately()) {
|
2013-05-02 07:58:00 -07:00
|
|
|
|
DrawScrollbar(cgContext, macRect, aFrame);
|
|
|
|
|
}
|
2007-04-10 17:25:11 -07:00
|
|
|
|
break;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
case NS_THEME_SCROLLBAR_THUMB_VERTICAL:
|
|
|
|
|
case NS_THEME_SCROLLBAR_THUMB_HORIZONTAL:
|
2014-05-28 06:22:16 -07:00
|
|
|
|
if (ScrollbarTrackAndThumbDrawSeparately()) {
|
|
|
|
|
BOOL isOverlay = nsLookAndFeel::UseOverlayScrollbars();
|
2013-05-02 07:58:00 -07:00
|
|
|
|
BOOL isHorizontal = (aWidgetType == NS_THEME_SCROLLBAR_THUMB_HORIZONTAL);
|
2014-05-28 06:22:16 -07:00
|
|
|
|
BOOL isRolledOver = IsParentScrollbarRolledOver(aFrame);
|
|
|
|
|
if (isOverlay && (!nsCocoaFeatures::OnMountainLionOrLater() || !isRolledOver)) {
|
2013-05-02 07:58:00 -07:00
|
|
|
|
if (isHorizontal) {
|
|
|
|
|
macRect.origin.y += 4;
|
|
|
|
|
macRect.size.height -= 4;
|
|
|
|
|
} else {
|
2013-06-26 21:00:41 -07:00
|
|
|
|
if (aFrame->StyleVisibility()->mDirection !=
|
|
|
|
|
NS_STYLE_DIRECTION_RTL) {
|
|
|
|
|
macRect.origin.x += 4;
|
|
|
|
|
}
|
2013-05-02 07:58:00 -07:00
|
|
|
|
macRect.size.width -= 4;
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-05-19 08:01:28 -07:00
|
|
|
|
const BOOL isOnTopOfDarkBackground = IsDarkBackground(aFrame);
|
2014-08-27 17:15:27 -07:00
|
|
|
|
// Scrollbar thumbs have a too high minimum width when rendered through
|
|
|
|
|
// NSAppearance on 10.10, so we call RenderWithCoreUILegacy here.
|
|
|
|
|
RenderWithCoreUILegacy(macRect, cgContext,
|
|
|
|
|
[NSDictionary dictionaryWithObjectsAndKeys:
|
2014-05-28 06:22:16 -07:00
|
|
|
|
(isOverlay ? @"kCUIWidgetOverlayScrollBar" : @"scrollbar"), @"widget",
|
2013-05-02 07:58:00 -07:00
|
|
|
|
@"regular", @"size",
|
2014-05-28 06:22:16 -07:00
|
|
|
|
(isRolledOver ? @"rollover" : @"normal"), @"state",
|
2013-05-02 07:58:00 -07:00
|
|
|
|
(isHorizontal ? @"kCUIOrientHorizontal" : @"kCUIOrientVertical"), @"kCUIOrientationKey",
|
2013-05-19 08:01:28 -07:00
|
|
|
|
(isOnTopOfDarkBackground ? @"kCUIVariantWhite" : @""), @"kCUIVariantKey",
|
2013-05-02 07:58:00 -07:00
|
|
|
|
[NSNumber numberWithBool:YES], @"indiconly",
|
|
|
|
|
[NSNumber numberWithBool:YES], @"kCUIThumbProportionKey",
|
|
|
|
|
[NSNumber numberWithBool:YES], @"is.flipped",
|
2014-08-27 17:15:27 -07:00
|
|
|
|
nil]);
|
2013-05-02 07:58:00 -07:00
|
|
|
|
}
|
|
|
|
|
break;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
case NS_THEME_SCROLLBAR_BUTTON_UP:
|
2007-04-10 17:25:11 -07:00
|
|
|
|
case NS_THEME_SCROLLBAR_BUTTON_LEFT:
|
|
|
|
|
#if SCROLLBARS_VISUAL_DEBUG
|
|
|
|
|
CGContextSetRGBFillColor(cgContext, 1.0, 0, 0, 0.6);
|
|
|
|
|
CGContextFillRect(cgContext, macRect);
|
2013-05-02 05:33:54 -07:00
|
|
|
|
#endif
|
2013-05-02 07:58:00 -07:00
|
|
|
|
break;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
case NS_THEME_SCROLLBAR_BUTTON_DOWN:
|
2007-04-10 17:25:11 -07:00
|
|
|
|
case NS_THEME_SCROLLBAR_BUTTON_RIGHT:
|
|
|
|
|
#if SCROLLBARS_VISUAL_DEBUG
|
|
|
|
|
CGContextSetRGBFillColor(cgContext, 0, 1.0, 0, 0.6);
|
|
|
|
|
CGContextFillRect(cgContext, macRect);
|
|
|
|
|
#endif
|
2013-05-02 07:58:00 -07:00
|
|
|
|
break;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
case NS_THEME_SCROLLBAR_TRACK_HORIZONTAL:
|
|
|
|
|
case NS_THEME_SCROLLBAR_TRACK_VERTICAL:
|
2014-05-28 06:22:16 -07:00
|
|
|
|
if (ScrollbarTrackAndThumbDrawSeparately()) {
|
|
|
|
|
BOOL isOverlay = nsLookAndFeel::UseOverlayScrollbars();
|
|
|
|
|
if (!isOverlay || IsParentScrollbarRolledOver(aFrame)) {
|
|
|
|
|
BOOL isHorizontal = (aWidgetType == NS_THEME_SCROLLBAR_TRACK_HORIZONTAL);
|
|
|
|
|
if (isOverlay && !nsCocoaFeatures::OnMountainLionOrLater()) {
|
|
|
|
|
// On OSX 10.7, scrollbars don't grow when hovered.
|
|
|
|
|
// The adjustments below were obtained by trial and error.
|
|
|
|
|
if (isHorizontal) {
|
|
|
|
|
macRect.origin.y += 2.0;
|
2013-08-21 13:33:55 -07:00
|
|
|
|
} else {
|
2014-05-28 06:22:16 -07:00
|
|
|
|
if (aFrame->StyleVisibility()->mDirection !=
|
|
|
|
|
NS_STYLE_DIRECTION_RTL) {
|
|
|
|
|
macRect.origin.x += 3.0;
|
|
|
|
|
} else {
|
|
|
|
|
macRect.origin.x -= 1.0;
|
|
|
|
|
}
|
2013-08-21 13:33:55 -07:00
|
|
|
|
}
|
2013-08-21 12:44:17 -07:00
|
|
|
|
}
|
2014-05-28 06:22:16 -07:00
|
|
|
|
const BOOL isOnTopOfDarkBackground = IsDarkBackground(aFrame);
|
2014-08-27 17:15:27 -07:00
|
|
|
|
RenderWithCoreUILegacy(macRect, cgContext,
|
|
|
|
|
[NSDictionary dictionaryWithObjectsAndKeys:
|
2014-05-28 06:22:16 -07:00
|
|
|
|
(isOverlay ? @"kCUIWidgetOverlayScrollBar" : @"scrollbar"), @"widget",
|
|
|
|
|
@"regular", @"size",
|
|
|
|
|
(isHorizontal ? @"kCUIOrientHorizontal" : @"kCUIOrientVertical"), @"kCUIOrientationKey",
|
|
|
|
|
(isOnTopOfDarkBackground ? @"kCUIVariantWhite" : @""), @"kCUIVariantKey",
|
|
|
|
|
[NSNumber numberWithBool:YES], @"noindicator",
|
|
|
|
|
[NSNumber numberWithBool:YES], @"kCUIThumbProportionKey",
|
|
|
|
|
[NSNumber numberWithBool:YES], @"is.flipped",
|
2014-08-27 17:15:27 -07:00
|
|
|
|
nil]);
|
2013-08-21 12:44:17 -07:00
|
|
|
|
}
|
2013-05-02 07:58:00 -07:00
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
break;
|
2007-05-06 19:06:58 -07:00
|
|
|
|
|
|
|
|
|
case NS_THEME_TEXTFIELD_MULTILINE: {
|
|
|
|
|
// we have to draw this by hand because there is no HITheme value for it
|
|
|
|
|
CGContextSetRGBFillColor(cgContext, 1.0, 1.0, 1.0, 1.0);
|
|
|
|
|
|
|
|
|
|
CGContextFillRect(cgContext, macRect);
|
|
|
|
|
|
2014-10-07 07:18:02 -07:00
|
|
|
|
// #737373 for the top border, #999999 for the rest.
|
|
|
|
|
float x = macRect.origin.x, y = macRect.origin.y;
|
|
|
|
|
float w = macRect.size.width, h = macRect.size.height;
|
|
|
|
|
CGContextSetRGBFillColor(cgContext, 0.4510, 0.4510, 0.4510, 1.0);
|
|
|
|
|
CGContextFillRect(cgContext, CGRectMake(x, y, w, 1));
|
|
|
|
|
CGContextSetRGBFillColor(cgContext, 0.6, 0.6, 0.6, 1.0);
|
|
|
|
|
CGContextFillRect(cgContext, CGRectMake(x, y + 1, 1, h - 1));
|
|
|
|
|
CGContextFillRect(cgContext, CGRectMake(x + w - 1, y + 1, 1, h - 1));
|
|
|
|
|
CGContextFillRect(cgContext, CGRectMake(x + 1, y + h - 1, w - 2, 1));
|
2008-02-07 03:39:04 -08:00
|
|
|
|
|
|
|
|
|
// draw a focus ring
|
2010-10-20 04:26:32 -07:00
|
|
|
|
if (eventState.HasState(NS_EVENT_STATE_FOCUS)) {
|
2014-10-07 07:18:02 -07:00
|
|
|
|
NSGraphicsContext* savedContext = [NSGraphicsContext currentContext];
|
|
|
|
|
[NSGraphicsContext setCurrentContext:[NSGraphicsContext graphicsContextWithGraphicsPort:cgContext flipped:YES]];
|
|
|
|
|
CGContextSaveGState(cgContext);
|
|
|
|
|
NSSetFocusRingStyle(NSFocusRingOnly);
|
|
|
|
|
NSRectFill(NSRectFromCGRect(macRect));
|
|
|
|
|
CGContextRestoreGState(cgContext);
|
|
|
|
|
[NSGraphicsContext setCurrentContext:savedContext];
|
2008-02-07 03:39:04 -08:00
|
|
|
|
}
|
2007-05-06 19:06:58 -07:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
2010-08-02 06:24:53 -07:00
|
|
|
|
case NS_THEME_LISTBOX: {
|
|
|
|
|
// We have to draw this by hand because kHIThemeFrameListBox drawing
|
|
|
|
|
// is buggy on 10.5, see bug 579259.
|
2007-03-22 10:30:00 -07:00
|
|
|
|
CGContextSetRGBFillColor(cgContext, 1.0, 1.0, 1.0, 1.0);
|
|
|
|
|
CGContextFillRect(cgContext, macRect);
|
2010-08-02 06:24:53 -07:00
|
|
|
|
|
|
|
|
|
// #8E8E8E for the top border, #BEBEBE for the rest.
|
2012-08-13 09:45:57 -07:00
|
|
|
|
float x = macRect.origin.x, y = macRect.origin.y;
|
|
|
|
|
float w = macRect.size.width, h = macRect.size.height;
|
2010-08-02 06:24:53 -07:00
|
|
|
|
CGContextSetRGBFillColor(cgContext, 0.557, 0.557, 0.557, 1.0);
|
|
|
|
|
CGContextFillRect(cgContext, CGRectMake(x, y, w, 1));
|
|
|
|
|
CGContextSetRGBFillColor(cgContext, 0.745, 0.745, 0.745, 1.0);
|
|
|
|
|
CGContextFillRect(cgContext, CGRectMake(x, y + 1, 1, h - 1));
|
|
|
|
|
CGContextFillRect(cgContext, CGRectMake(x + w - 1, y + 1, 1, h - 1));
|
|
|
|
|
CGContextFillRect(cgContext, CGRectMake(x + 1, y + h - 1, w - 2, 1));
|
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
break;
|
|
|
|
|
|
2008-11-27 14:16:13 -08:00
|
|
|
|
case NS_THEME_TAB:
|
2011-08-08 07:42:45 -07:00
|
|
|
|
DrawSegment(cgContext, macRect, eventState, aFrame, tabRenderSettings);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case NS_THEME_TAB_PANELS:
|
2008-09-22 01:57:42 -07:00
|
|
|
|
DrawTabPanel(cgContext, macRect, aFrame);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
break;
|
2009-08-20 07:19:18 -07:00
|
|
|
|
|
|
|
|
|
case NS_THEME_RESIZER:
|
2009-09-27 14:58:58 -07:00
|
|
|
|
DrawResizer(cgContext, macRect, aFrame);
|
2009-08-20 07:19:18 -07:00
|
|
|
|
break;
|
2014-10-07 07:18:01 -07:00
|
|
|
|
|
|
|
|
|
case NS_THEME_MAC_VIBRANCY_LIGHT:
|
|
|
|
|
case NS_THEME_MAC_VIBRANCY_DARK:
|
|
|
|
|
{
|
|
|
|
|
NSWindow* win = NativeWindowForFrame(aFrame);
|
|
|
|
|
if ([win isKindOfClass:[ToolbarWindow class]]) {
|
|
|
|
|
NSGraphicsContext* savedContext = [NSGraphicsContext currentContext];
|
|
|
|
|
[NSGraphicsContext setCurrentContext:[NSGraphicsContext graphicsContextWithGraphicsPort:cgContext flipped:YES]];
|
|
|
|
|
|
|
|
|
|
ChildView* childView = [(ToolbarWindow*)win mainChildView];
|
|
|
|
|
[[childView vibrancyFillColorForWidgetType:aWidgetType] set];
|
|
|
|
|
NSRectFill(NSRectFromCGRect(macRect));
|
|
|
|
|
|
|
|
|
|
[NSGraphicsContext setCurrentContext:savedContext];
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
}
|
|
|
|
|
|
2014-09-30 04:51:54 -07:00
|
|
|
|
if (hidpi) {
|
|
|
|
|
// Reset the base CTM.
|
|
|
|
|
CGContextSetBaseCTM(cgContext, CGAffineTransformIdentity);
|
|
|
|
|
}
|
|
|
|
|
|
2008-02-20 03:33:27 -08:00
|
|
|
|
nativeDrawing.EndNativeDrawing();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
|
|
return NS_OK;
|
2008-02-20 17:01:27 -08:00
|
|
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
}
|
|
|
|
|
|
2009-04-17 01:12:12 -07:00
|
|
|
|
nsIntMargin
|
|
|
|
|
nsNativeThemeCocoa::RTLAwareMargin(const nsIntMargin& aMargin, nsIFrame* aFrame)
|
|
|
|
|
{
|
2013-03-06 00:05:55 -08:00
|
|
|
|
if (IsFrameRTL(aFrame)) {
|
|
|
|
|
// Return a copy of aMargin w/ right & left reversed:
|
|
|
|
|
return nsIntMargin(aMargin.top, aMargin.left,
|
|
|
|
|
aMargin.bottom, aMargin.right);
|
|
|
|
|
}
|
2009-04-17 01:12:12 -07:00
|
|
|
|
|
|
|
|
|
return aMargin;
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-06 00:05:55 -08:00
|
|
|
|
static const nsIntMargin kAquaDropdownBorder(1, 22, 2, 5);
|
|
|
|
|
static const nsIntMargin kAquaComboboxBorder(3, 20, 3, 4);
|
|
|
|
|
static const nsIntMargin kAquaSearchfieldBorder(3, 5, 2, 19);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-04-16 18:22:44 -07:00
|
|
|
|
nsNativeThemeCocoa::GetWidgetBorder(nsDeviceContext* aContext,
|
2007-03-22 10:30:00 -07:00
|
|
|
|
nsIFrame* aFrame,
|
2012-08-22 08:56:38 -07:00
|
|
|
|
uint8_t aWidgetType,
|
2009-01-14 19:27:09 -08:00
|
|
|
|
nsIntMargin* aResult)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
{
|
2008-02-20 17:01:27 -08:00
|
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
|
aResult->SizeTo(0, 0, 0, 0);
|
|
|
|
|
|
|
|
|
|
switch (aWidgetType) {
|
|
|
|
|
case NS_THEME_BUTTON:
|
2007-12-23 11:22:47 -08:00
|
|
|
|
{
|
2009-08-10 14:23:50 -07:00
|
|
|
|
if (IsButtonTypeMenu(aFrame)) {
|
|
|
|
|
*aResult = RTLAwareMargin(kAquaDropdownBorder, aFrame);
|
|
|
|
|
} else {
|
2013-03-06 00:05:55 -08:00
|
|
|
|
aResult->SizeTo(1, 7, 3, 7);
|
2009-08-10 14:23:50 -07:00
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
break;
|
2007-12-23 11:22:47 -08:00
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
2011-08-08 07:42:45 -07:00
|
|
|
|
case NS_THEME_TOOLBAR_BUTTON:
|
|
|
|
|
{
|
2013-03-06 00:05:55 -08:00
|
|
|
|
aResult->SizeTo(1, 4, 1, 4);
|
2011-08-08 07:42:45 -07:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-11 06:48:30 -08:00
|
|
|
|
case NS_THEME_CHECKBOX:
|
|
|
|
|
case NS_THEME_RADIO:
|
|
|
|
|
{
|
|
|
|
|
// nsFormControlFrame::GetIntrinsicWidth and nsFormControlFrame::GetIntrinsicHeight
|
|
|
|
|
// assume a border width of 2px.
|
|
|
|
|
aResult->SizeTo(2, 2, 2, 2);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
|
case NS_THEME_DROPDOWN:
|
|
|
|
|
case NS_THEME_DROPDOWN_BUTTON:
|
2009-04-17 01:12:12 -07:00
|
|
|
|
*aResult = RTLAwareMargin(kAquaDropdownBorder, aFrame);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
break;
|
2007-09-03 08:25:15 -07:00
|
|
|
|
|
2009-02-11 07:54:10 -08:00
|
|
|
|
case NS_THEME_DROPDOWN_TEXTFIELD:
|
2009-04-17 01:12:12 -07:00
|
|
|
|
*aResult = RTLAwareMargin(kAquaComboboxBorder, aFrame);
|
2009-02-11 07:54:10 -08:00
|
|
|
|
break;
|
|
|
|
|
|
2013-12-08 15:23:28 -08:00
|
|
|
|
case NS_THEME_NUMBER_INPUT:
|
2007-09-03 08:25:15 -07:00
|
|
|
|
case NS_THEME_TEXTFIELD:
|
|
|
|
|
{
|
2007-03-22 10:30:00 -07:00
|
|
|
|
SInt32 frameOutset = 0;
|
|
|
|
|
::GetThemeMetric(kThemeMetricEditTextFrameOutset, &frameOutset);
|
2007-09-03 08:25:15 -07:00
|
|
|
|
|
|
|
|
|
SInt32 textPadding = 0;
|
|
|
|
|
::GetThemeMetric(kThemeMetricEditTextWhitespace, &textPadding);
|
|
|
|
|
|
|
|
|
|
frameOutset += textPadding;
|
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
|
aResult->SizeTo(frameOutset, frameOutset, frameOutset, frameOutset);
|
|
|
|
|
break;
|
2007-09-03 08:25:15 -07:00
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
2007-05-06 19:06:58 -07:00
|
|
|
|
case NS_THEME_TEXTFIELD_MULTILINE:
|
|
|
|
|
aResult->SizeTo(1, 1, 1, 1);
|
|
|
|
|
break;
|
2007-09-03 08:25:15 -07:00
|
|
|
|
|
2008-12-06 03:40:58 -08:00
|
|
|
|
case NS_THEME_SEARCHFIELD:
|
2009-04-17 01:12:12 -07:00
|
|
|
|
*aResult = RTLAwareMargin(kAquaSearchfieldBorder, aFrame);
|
2008-12-06 03:40:58 -08:00
|
|
|
|
break;
|
|
|
|
|
|
2007-09-03 08:25:15 -07:00
|
|
|
|
case NS_THEME_LISTBOX:
|
|
|
|
|
{
|
2007-03-22 10:30:00 -07:00
|
|
|
|
SInt32 frameOutset = 0;
|
|
|
|
|
::GetThemeMetric(kThemeMetricListBoxFrameOutset, &frameOutset);
|
|
|
|
|
aResult->SizeTo(frameOutset, frameOutset, frameOutset, frameOutset);
|
|
|
|
|
break;
|
2007-09-03 08:25:15 -07:00
|
|
|
|
}
|
2007-05-06 19:06:58 -07:00
|
|
|
|
|
2007-04-10 17:25:11 -07:00
|
|
|
|
case NS_THEME_SCROLLBAR_TRACK_HORIZONTAL:
|
|
|
|
|
case NS_THEME_SCROLLBAR_TRACK_VERTICAL:
|
|
|
|
|
{
|
2013-05-02 07:58:00 -07:00
|
|
|
|
bool isHorizontal = (aWidgetType == NS_THEME_SCROLLBAR_TRACK_HORIZONTAL);
|
|
|
|
|
|
2011-05-16 10:56:03 -07:00
|
|
|
|
// On Lion and later, scrollbars have no arrows.
|
2012-05-17 00:53:20 -07:00
|
|
|
|
if (!nsCocoaFeatures::OnLionOrLater()) {
|
2011-05-16 10:56:03 -07:00
|
|
|
|
// There's only an endcap to worry about when both arrows are on the bottom
|
|
|
|
|
NSString *buttonPlacement = [[NSUserDefaults standardUserDefaults] objectForKey:@"AppleScrollBarVariant"];
|
|
|
|
|
if (!buttonPlacement || [buttonPlacement isEqualToString:@"DoubleMax"]) {
|
|
|
|
|
nsIFrame *scrollbarFrame = GetParentScrollbarFrame(aFrame);
|
|
|
|
|
if (!scrollbarFrame) return NS_ERROR_FAILURE;
|
2013-02-16 13:51:02 -08:00
|
|
|
|
bool isSmall = (scrollbarFrame->StyleDisplay()->mAppearance == NS_THEME_SCROLLBAR_SMALL);
|
2011-05-16 10:56:03 -07:00
|
|
|
|
|
|
|
|
|
// There isn't a metric for this, so just hardcode a best guess at the value.
|
|
|
|
|
// This value is even less exact due to the fact that the endcap is partially concave.
|
2012-08-22 08:56:38 -07:00
|
|
|
|
int32_t endcapSize = isSmall ? 5 : 6;
|
2011-05-16 10:56:03 -07:00
|
|
|
|
|
|
|
|
|
if (isHorizontal)
|
2013-03-06 00:05:55 -08:00
|
|
|
|
aResult->SizeTo(0, 0, 0, endcapSize);
|
2011-05-16 10:56:03 -07:00
|
|
|
|
else
|
2013-03-06 00:05:55 -08:00
|
|
|
|
aResult->SizeTo(endcapSize, 0, 0, 0);
|
2011-05-16 10:56:03 -07:00
|
|
|
|
}
|
2007-04-10 17:25:11 -07:00
|
|
|
|
}
|
2013-05-02 07:58:00 -07:00
|
|
|
|
|
2013-06-07 12:44:24 -07:00
|
|
|
|
if (nsLookAndFeel::UseOverlayScrollbars()) {
|
2013-05-02 07:58:00 -07:00
|
|
|
|
if (isHorizontal) {
|
|
|
|
|
aResult->SizeTo(2, 1, 1, 1);
|
2013-05-14 12:54:57 -07:00
|
|
|
|
} else {
|
|
|
|
|
aResult->SizeTo(1, 1, 1, 2);
|
2013-05-02 07:58:00 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-04-10 17:25:11 -07:00
|
|
|
|
break;
|
2007-09-03 08:25:15 -07:00
|
|
|
|
}
|
2008-09-16 01:21:06 -07:00
|
|
|
|
|
2009-01-06 07:46:59 -08:00
|
|
|
|
case NS_THEME_STATUSBAR:
|
2013-03-06 00:05:55 -08:00
|
|
|
|
aResult->SizeTo(1, 0, 0, 0);
|
2008-09-16 01:21:06 -07:00
|
|
|
|
break;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
}
|
2007-09-03 08:25:15 -07:00
|
|
|
|
|
2014-06-19 23:42:30 -07:00
|
|
|
|
if (IsHiDPIContext(aFrame->PresContext())) {
|
2012-08-13 09:45:57 -07:00
|
|
|
|
*aResult = *aResult + *aResult; // doubled
|
|
|
|
|
}
|
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
|
return NS_OK;
|
2008-02-20 17:01:27 -08:00
|
|
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
}
|
|
|
|
|
|
2011-09-30 17:20:33 -07:00
|
|
|
|
// Return false here to indicate that CSS padding values should be used. There is
|
2007-09-03 08:25:15 -07:00
|
|
|
|
// no reason to make a distinction between padding and border values, just specify
|
2011-09-30 17:20:33 -07:00
|
|
|
|
// whatever values you want in GetWidgetBorder and only use this to return true
|
2007-09-03 08:25:15 -07:00
|
|
|
|
// if you want to override CSS padding values.
|
2011-09-28 23:19:26 -07:00
|
|
|
|
bool
|
2011-04-16 18:22:44 -07:00
|
|
|
|
nsNativeThemeCocoa::GetWidgetPadding(nsDeviceContext* aContext,
|
2007-03-22 10:30:00 -07:00
|
|
|
|
nsIFrame* aFrame,
|
2012-08-22 08:56:38 -07:00
|
|
|
|
uint8_t aWidgetType,
|
2009-01-14 19:27:09 -08:00
|
|
|
|
nsIntMargin* aResult)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
{
|
2007-11-17 11:33:51 -08:00
|
|
|
|
// We don't want CSS padding being used for certain widgets.
|
|
|
|
|
// See bug 381639 for an example of why.
|
2008-03-07 09:57:34 -08:00
|
|
|
|
switch (aWidgetType) {
|
|
|
|
|
case NS_THEME_BUTTON:
|
|
|
|
|
// Radios and checkboxes return a fixed size in GetMinimumWidgetSize
|
|
|
|
|
// and have a meaningful baseline, so they can't have
|
|
|
|
|
// author-specified padding.
|
|
|
|
|
case NS_THEME_CHECKBOX:
|
|
|
|
|
case NS_THEME_RADIO:
|
|
|
|
|
aResult->SizeTo(0, 0, 0, 0);
|
2011-09-30 17:20:33 -07:00
|
|
|
|
return true;
|
2007-11-17 11:33:51 -08:00
|
|
|
|
}
|
2011-09-30 17:20:33 -07:00
|
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
}
|
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
|
bool
|
2011-04-16 18:22:44 -07:00
|
|
|
|
nsNativeThemeCocoa::GetWidgetOverflow(nsDeviceContext* aContext, nsIFrame* aFrame,
|
2012-08-22 08:56:38 -07:00
|
|
|
|
uint8_t aWidgetType, nsRect* aOverflowRect)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
{
|
2014-06-19 23:42:30 -07:00
|
|
|
|
int32_t p2a = aFrame->PresContext()->AppUnitsPerDevPixel();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
switch (aWidgetType) {
|
|
|
|
|
case NS_THEME_BUTTON:
|
2014-02-27 09:12:16 -08:00
|
|
|
|
case NS_THEME_MOZ_MAC_HELP_BUTTON:
|
2011-08-08 07:42:45 -07:00
|
|
|
|
case NS_THEME_TOOLBAR_BUTTON:
|
2013-12-08 15:23:28 -08:00
|
|
|
|
case NS_THEME_NUMBER_INPUT:
|
2007-03-22 10:30:00 -07:00
|
|
|
|
case NS_THEME_TEXTFIELD:
|
2007-05-06 19:06:58 -07:00
|
|
|
|
case NS_THEME_TEXTFIELD_MULTILINE:
|
2008-12-06 03:40:58 -08:00
|
|
|
|
case NS_THEME_SEARCHFIELD:
|
2007-03-22 10:30:00 -07:00
|
|
|
|
case NS_THEME_LISTBOX:
|
|
|
|
|
case NS_THEME_DROPDOWN:
|
|
|
|
|
case NS_THEME_DROPDOWN_BUTTON:
|
2009-02-11 07:54:10 -08:00
|
|
|
|
case NS_THEME_DROPDOWN_TEXTFIELD:
|
2007-03-22 10:30:00 -07:00
|
|
|
|
case NS_THEME_CHECKBOX:
|
|
|
|
|
case NS_THEME_RADIO:
|
2008-11-27 14:16:13 -08:00
|
|
|
|
case NS_THEME_TAB:
|
2007-03-22 10:30:00 -07:00
|
|
|
|
{
|
|
|
|
|
// We assume that the above widgets can draw a focus ring that will be less than
|
|
|
|
|
// or equal to 4 pixels thick.
|
2013-03-06 00:05:55 -08:00
|
|
|
|
nsIntMargin extraSize = nsIntMargin(MAX_FOCUS_RING_WIDTH,
|
|
|
|
|
MAX_FOCUS_RING_WIDTH,
|
|
|
|
|
MAX_FOCUS_RING_WIDTH,
|
|
|
|
|
MAX_FOCUS_RING_WIDTH);
|
|
|
|
|
nsMargin m(NSIntPixelsToAppUnits(extraSize.top, p2a),
|
2007-03-22 10:30:00 -07:00
|
|
|
|
NSIntPixelsToAppUnits(extraSize.right, p2a),
|
2013-03-06 00:05:55 -08:00
|
|
|
|
NSIntPixelsToAppUnits(extraSize.bottom, p2a),
|
|
|
|
|
NSIntPixelsToAppUnits(extraSize.left, p2a));
|
2008-04-01 16:34:20 -07:00
|
|
|
|
aOverflowRect->Inflate(m);
|
2011-09-30 17:20:33 -07:00
|
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
}
|
2012-05-05 09:41:50 -07:00
|
|
|
|
case NS_THEME_PROGRESSBAR:
|
|
|
|
|
{
|
|
|
|
|
// Progress bars draw a 2 pixel white shadow under their progress indicators
|
2013-03-06 00:05:55 -08:00
|
|
|
|
nsMargin m(0, 0, NSIntPixelsToAppUnits(2, p2a), 0);
|
2012-05-05 09:41:50 -07:00
|
|
|
|
aOverflowRect->Inflate(m);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2014-06-14 05:48:08 -07:00
|
|
|
|
case NS_THEME_FOCUS_OUTLINE:
|
|
|
|
|
{
|
|
|
|
|
aOverflowRect->Inflate(NSIntPixelsToAppUnits(2, p2a));
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
}
|
|
|
|
|
|
2011-09-30 17:20:33 -07:00
|
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
}
|
|
|
|
|
|
2013-05-02 07:58:00 -07:00
|
|
|
|
static const int32_t kRegularScrollbarThumbMinSize = 26;
|
2013-05-21 12:58:00 -07:00
|
|
|
|
static const int32_t kSmallScrollbarThumbMinSize = 26;
|
2009-10-05 20:02:50 -07:00
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
|
NS_IMETHODIMP
|
2014-06-27 02:19:00 -07:00
|
|
|
|
nsNativeThemeCocoa::GetMinimumWidgetSize(nsPresContext* aPresContext,
|
2007-03-22 10:30:00 -07:00
|
|
|
|
nsIFrame* aFrame,
|
2012-08-22 08:56:38 -07:00
|
|
|
|
uint8_t aWidgetType,
|
2009-01-14 19:27:09 -08:00
|
|
|
|
nsIntSize* aResult,
|
2011-09-28 23:19:26 -07:00
|
|
|
|
bool* aIsOverridable)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
{
|
2008-02-20 17:01:27 -08:00
|
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
|
aResult->SizeTo(0,0);
|
2011-09-30 17:20:33 -07:00
|
|
|
|
*aIsOverridable = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
|
|
switch (aWidgetType) {
|
|
|
|
|
case NS_THEME_BUTTON:
|
|
|
|
|
{
|
2009-01-12 11:22:59 -08:00
|
|
|
|
aResult->SizeTo(pushButtonSettings.minimumSizes[miniControlSize].width,
|
|
|
|
|
pushButtonSettings.naturalSizes[miniControlSize].height);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-08 02:45:00 -07:00
|
|
|
|
case NS_THEME_BUTTON_ARROW_UP:
|
|
|
|
|
case NS_THEME_BUTTON_ARROW_DOWN:
|
|
|
|
|
{
|
|
|
|
|
aResult->SizeTo(kMenuScrollArrowSize.width, kMenuScrollArrowSize.height);
|
|
|
|
|
*aIsOverridable = false;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case NS_THEME_MENUARROW:
|
|
|
|
|
{
|
|
|
|
|
aResult->SizeTo(kMenuarrowSize.width, kMenuarrowSize.height);
|
|
|
|
|
*aIsOverridable = false;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-27 09:12:16 -08:00
|
|
|
|
case NS_THEME_MOZ_MAC_HELP_BUTTON:
|
|
|
|
|
{
|
|
|
|
|
aResult->SizeTo(kHelpButtonSize.width, kHelpButtonSize.height);
|
|
|
|
|
*aIsOverridable = false;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-08 07:42:45 -07:00
|
|
|
|
case NS_THEME_TOOLBAR_BUTTON:
|
|
|
|
|
{
|
|
|
|
|
aResult->SizeTo(0, toolbarButtonHeights[miniControlSize]);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
|
case NS_THEME_SPINNER:
|
2013-12-05 08:20:34 -08:00
|
|
|
|
case NS_THEME_SPINNER_UP_BUTTON:
|
|
|
|
|
case NS_THEME_SPINNER_DOWN_BUTTON:
|
2007-03-22 10:30:00 -07:00
|
|
|
|
{
|
2007-09-18 02:17:51 -07:00
|
|
|
|
SInt32 buttonHeight = 0, buttonWidth = 0;
|
2013-12-05 08:20:34 -08:00
|
|
|
|
if (aFrame->GetContent()->IsXUL()) {
|
|
|
|
|
::GetThemeMetric(kThemeMetricLittleArrowsWidth, &buttonWidth);
|
|
|
|
|
::GetThemeMetric(kThemeMetricLittleArrowsHeight, &buttonHeight);
|
|
|
|
|
} else {
|
|
|
|
|
NSSize size =
|
|
|
|
|
spinnerSettings.minimumSizes[EnumSizeForCocoaSize(NSMiniControlSize)];
|
|
|
|
|
buttonWidth = size.width;
|
|
|
|
|
buttonHeight = size.height;
|
|
|
|
|
if (aWidgetType != NS_THEME_SPINNER) {
|
|
|
|
|
// the buttons are half the height of the spinner
|
|
|
|
|
buttonHeight /= 2;
|
|
|
|
|
}
|
|
|
|
|
}
|
2007-09-18 02:17:51 -07:00
|
|
|
|
aResult->SizeTo(buttonWidth, buttonHeight);
|
2013-12-05 08:20:34 -08:00
|
|
|
|
*aIsOverridable = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case NS_THEME_DROPDOWN:
|
|
|
|
|
case NS_THEME_DROPDOWN_BUTTON:
|
|
|
|
|
{
|
|
|
|
|
SInt32 popupHeight = 0;
|
|
|
|
|
::GetThemeMetric(kThemeMetricPopupButtonHeight, &popupHeight);
|
|
|
|
|
aResult->SizeTo(0, popupHeight);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2013-12-08 15:23:28 -08:00
|
|
|
|
|
|
|
|
|
case NS_THEME_NUMBER_INPUT:
|
2007-03-22 10:30:00 -07:00
|
|
|
|
case NS_THEME_TEXTFIELD:
|
2007-05-06 19:06:58 -07:00
|
|
|
|
case NS_THEME_TEXTFIELD_MULTILINE:
|
2008-12-06 03:40:58 -08:00
|
|
|
|
case NS_THEME_SEARCHFIELD:
|
2007-03-22 10:30:00 -07:00
|
|
|
|
{
|
|
|
|
|
// at minimum, we should be tall enough for 9pt text.
|
|
|
|
|
// I'm using hardcoded values here because the appearance manager
|
|
|
|
|
// values for the frame size are incorrect.
|
|
|
|
|
aResult->SizeTo(0, (2 + 2) /* top */ + 9 + (1 + 1) /* bottom */);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2013-05-02 11:15:29 -07:00
|
|
|
|
|
|
|
|
|
case NS_THEME_WINDOW_BUTTON_BOX: {
|
2013-06-12 14:42:00 -07:00
|
|
|
|
NSSize size = WindowButtonsSize(aFrame);
|
|
|
|
|
aResult->SizeTo(size.width, size.height);
|
|
|
|
|
*aIsOverridable = false;
|
2013-05-02 11:15:29 -07:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case NS_THEME_MOZ_MAC_FULLSCREEN_BUTTON: {
|
2014-08-20 08:10:33 -07:00
|
|
|
|
if ([NativeWindowForFrame(aFrame) respondsToSelector:@selector(toggleFullScreen:)] &&
|
|
|
|
|
!nsCocoaFeatures::OnYosemiteOrLater()) {
|
2013-06-07 02:54:35 -07:00
|
|
|
|
// This value is hardcoded because it's needed before we can measure the
|
|
|
|
|
// position and size of the fullscreen button.
|
2013-06-12 14:42:00 -07:00
|
|
|
|
aResult->SizeTo(16, 17);
|
2013-06-07 02:54:35 -07:00
|
|
|
|
}
|
2013-06-12 14:42:00 -07:00
|
|
|
|
*aIsOverridable = false;
|
2013-05-02 11:15:29 -07:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
|
case NS_THEME_PROGRESSBAR:
|
|
|
|
|
{
|
|
|
|
|
SInt32 barHeight = 0;
|
|
|
|
|
::GetThemeMetric(kThemeMetricNormalProgressBarThickness, &barHeight);
|
|
|
|
|
aResult->SizeTo(0, barHeight);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case NS_THEME_TREEVIEW_TWISTY:
|
|
|
|
|
case NS_THEME_TREEVIEW_TWISTY_OPEN:
|
|
|
|
|
{
|
|
|
|
|
SInt32 twistyHeight = 0, twistyWidth = 0;
|
|
|
|
|
::GetThemeMetric(kThemeMetricDisclosureButtonWidth, &twistyWidth);
|
|
|
|
|
::GetThemeMetric(kThemeMetricDisclosureButtonHeight, &twistyHeight);
|
|
|
|
|
aResult->SizeTo(twistyWidth, twistyHeight);
|
2011-09-30 17:20:33 -07:00
|
|
|
|
*aIsOverridable = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case NS_THEME_TREEVIEW_HEADER:
|
|
|
|
|
case NS_THEME_TREEVIEW_HEADER_CELL:
|
|
|
|
|
{
|
|
|
|
|
SInt32 headerHeight = 0;
|
|
|
|
|
::GetThemeMetric(kThemeMetricListHeaderHeight, &headerHeight);
|
2008-11-27 14:14:54 -08:00
|
|
|
|
aResult->SizeTo(0, headerHeight - 1); // We don't need the top border.
|
2007-03-22 10:30:00 -07:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2008-11-27 14:16:13 -08:00
|
|
|
|
case NS_THEME_TAB:
|
|
|
|
|
{
|
2011-08-08 07:42:45 -07:00
|
|
|
|
aResult->SizeTo(0, tabHeights[miniControlSize]);
|
2008-11-27 14:16:13 -08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-15 22:40:15 -07:00
|
|
|
|
case NS_THEME_RANGE:
|
|
|
|
|
{
|
|
|
|
|
// The Mac Appearance Manager API (the old API we're currently using)
|
|
|
|
|
// doesn't define constants to obtain a minimum size for sliders. We use
|
|
|
|
|
// the "thickness" of a slider that has default dimensions for both the
|
|
|
|
|
// minimum width and height to get something sane and so that paint
|
|
|
|
|
// invalidation works.
|
|
|
|
|
SInt32 size = 0;
|
|
|
|
|
if (IsRangeHorizontal(aFrame)) {
|
|
|
|
|
::GetThemeMetric(kThemeMetricHSliderHeight, &size);
|
|
|
|
|
} else {
|
|
|
|
|
::GetThemeMetric(kThemeMetricVSliderWidth, &size);
|
|
|
|
|
}
|
|
|
|
|
aResult->SizeTo(size, size);
|
|
|
|
|
*aIsOverridable = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case NS_THEME_RANGE_THUMB:
|
|
|
|
|
{
|
|
|
|
|
SInt32 width = 0;
|
|
|
|
|
SInt32 height = 0;
|
|
|
|
|
::GetThemeMetric(kThemeMetricSliderMinThumbWidth, &width);
|
|
|
|
|
::GetThemeMetric(kThemeMetricSliderMinThumbHeight, &height);
|
|
|
|
|
aResult->SizeTo(width, height);
|
|
|
|
|
*aIsOverridable = false;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
|
case NS_THEME_SCALE_HORIZONTAL:
|
|
|
|
|
{
|
|
|
|
|
SInt32 scaleHeight = 0;
|
|
|
|
|
::GetThemeMetric(kThemeMetricHSliderHeight, &scaleHeight);
|
|
|
|
|
aResult->SizeTo(scaleHeight, scaleHeight);
|
2011-09-30 17:20:33 -07:00
|
|
|
|
*aIsOverridable = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case NS_THEME_SCALE_VERTICAL:
|
|
|
|
|
{
|
|
|
|
|
SInt32 scaleWidth = 0;
|
|
|
|
|
::GetThemeMetric(kThemeMetricVSliderWidth, &scaleWidth);
|
|
|
|
|
aResult->SizeTo(scaleWidth, scaleWidth);
|
2011-09-30 17:20:33 -07:00
|
|
|
|
*aIsOverridable = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
break;
|
|
|
|
|
}
|
2007-04-10 17:25:11 -07:00
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
|
case NS_THEME_SCROLLBAR_THUMB_HORIZONTAL:
|
|
|
|
|
case NS_THEME_SCROLLBAR_THUMB_VERTICAL:
|
2007-04-10 17:25:11 -07:00
|
|
|
|
{
|
2009-10-05 20:02:50 -07:00
|
|
|
|
// Find our parent scrollbar frame in order to find out whether we're in
|
|
|
|
|
// a small or a large scrollbar.
|
2007-04-10 17:25:11 -07:00
|
|
|
|
nsIFrame *scrollbarFrame = GetParentScrollbarFrame(aFrame);
|
2009-10-05 20:02:50 -07:00
|
|
|
|
if (!scrollbarFrame)
|
|
|
|
|
return NS_ERROR_FAILURE;
|
2007-05-15 15:19:54 -07:00
|
|
|
|
|
2013-02-16 13:51:02 -08:00
|
|
|
|
bool isSmall = (scrollbarFrame->StyleDisplay()->mAppearance == NS_THEME_SCROLLBAR_SMALL);
|
2011-09-28 23:19:26 -07:00
|
|
|
|
bool isHorizontal = (aWidgetType == NS_THEME_SCROLLBAR_THUMB_HORIZONTAL);
|
2012-08-22 08:56:38 -07:00
|
|
|
|
int32_t& minSize = isHorizontal ? aResult->width : aResult->height;
|
2009-10-05 20:02:50 -07:00
|
|
|
|
minSize = isSmall ? kSmallScrollbarThumbMinSize : kRegularScrollbarThumbMinSize;
|
2007-04-10 17:25:11 -07:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case NS_THEME_SCROLLBAR:
|
2013-05-02 07:58:00 -07:00
|
|
|
|
case NS_THEME_SCROLLBAR_SMALL:
|
2007-03-22 10:30:00 -07:00
|
|
|
|
case NS_THEME_SCROLLBAR_TRACK_VERTICAL:
|
|
|
|
|
case NS_THEME_SCROLLBAR_TRACK_HORIZONTAL:
|
|
|
|
|
{
|
2013-05-02 07:58:00 -07:00
|
|
|
|
*aIsOverridable = false;
|
|
|
|
|
|
2013-06-07 12:44:24 -07:00
|
|
|
|
if (nsLookAndFeel::UseOverlayScrollbars()) {
|
2013-08-01 14:01:22 -07:00
|
|
|
|
nsIFrame* scrollbarFrame = GetParentScrollbarFrame(aFrame);
|
|
|
|
|
if (scrollbarFrame &&
|
|
|
|
|
scrollbarFrame->StyleDisplay()->mAppearance ==
|
|
|
|
|
NS_THEME_SCROLLBAR_SMALL) {
|
|
|
|
|
aResult->SizeTo(14, 14);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
aResult->SizeTo(16, 16);
|
|
|
|
|
}
|
2013-05-02 07:58:00 -07:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
|
// yeah, i know i'm cheating a little here, but i figure that it
|
|
|
|
|
// really doesn't matter if the scrollbar is vertical or horizontal
|
|
|
|
|
// and the width metric is a really good metric for every piece
|
|
|
|
|
// of the scrollbar.
|
2007-04-10 17:25:11 -07:00
|
|
|
|
|
|
|
|
|
nsIFrame *scrollbarFrame = GetParentScrollbarFrame(aFrame);
|
|
|
|
|
if (!scrollbarFrame) return NS_ERROR_FAILURE;
|
|
|
|
|
|
2013-02-16 13:51:02 -08:00
|
|
|
|
int32_t themeMetric = (scrollbarFrame->StyleDisplay()->mAppearance == NS_THEME_SCROLLBAR_SMALL) ?
|
2007-04-10 17:25:11 -07:00
|
|
|
|
kThemeMetricSmallScrollBarWidth :
|
|
|
|
|
kThemeMetricScrollBarWidth;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
SInt32 scrollbarWidth = 0;
|
2007-04-10 17:25:11 -07:00
|
|
|
|
::GetThemeMetric(themeMetric, &scrollbarWidth);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
aResult->SizeTo(scrollbarWidth, scrollbarWidth);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2007-04-10 17:25:11 -07:00
|
|
|
|
|
2013-05-29 13:28:42 -07:00
|
|
|
|
case NS_THEME_SCROLLBAR_NON_DISAPPEARING:
|
|
|
|
|
{
|
|
|
|
|
int32_t themeMetric = kThemeMetricScrollBarWidth;
|
|
|
|
|
|
|
|
|
|
if (aFrame) {
|
|
|
|
|
nsIFrame* scrollbarFrame = GetParentScrollbarFrame(aFrame);
|
|
|
|
|
if (scrollbarFrame &&
|
|
|
|
|
scrollbarFrame->StyleDisplay()->mAppearance ==
|
|
|
|
|
NS_THEME_SCROLLBAR_SMALL) {
|
|
|
|
|
// XXX We're interested in the width of non-disappearing scrollbars
|
|
|
|
|
// to leave enough space for a dropmarker in non-native styled
|
|
|
|
|
// comboboxes (bug 869314). It isn't clear to me if comboboxes can
|
|
|
|
|
// ever have small scrollbars.
|
|
|
|
|
themeMetric = kThemeMetricSmallScrollBarWidth;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SInt32 scrollbarWidth = 0;
|
|
|
|
|
::GetThemeMetric(themeMetric, &scrollbarWidth);
|
|
|
|
|
aResult->SizeTo(scrollbarWidth, scrollbarWidth);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2007-04-10 17:25:11 -07:00
|
|
|
|
case NS_THEME_SCROLLBAR_BUTTON_UP:
|
|
|
|
|
case NS_THEME_SCROLLBAR_BUTTON_DOWN:
|
|
|
|
|
case NS_THEME_SCROLLBAR_BUTTON_LEFT:
|
|
|
|
|
case NS_THEME_SCROLLBAR_BUTTON_RIGHT:
|
|
|
|
|
{
|
|
|
|
|
nsIFrame *scrollbarFrame = GetParentScrollbarFrame(aFrame);
|
|
|
|
|
if (!scrollbarFrame) return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
|
|
// Since there is no NS_THEME_SCROLLBAR_BUTTON_UP_SMALL we need to ask the parent what appearance style it has.
|
2013-02-16 13:51:02 -08:00
|
|
|
|
int32_t themeMetric = (scrollbarFrame->StyleDisplay()->mAppearance == NS_THEME_SCROLLBAR_SMALL) ?
|
2007-04-10 17:25:11 -07:00
|
|
|
|
kThemeMetricSmallScrollBarWidth :
|
|
|
|
|
kThemeMetricScrollBarWidth;
|
|
|
|
|
SInt32 scrollbarWidth = 0;
|
|
|
|
|
::GetThemeMetric(themeMetric, &scrollbarWidth);
|
|
|
|
|
|
|
|
|
|
// It seems that for both sizes of scrollbar, the buttons are one pixel "longer".
|
|
|
|
|
if (aWidgetType == NS_THEME_SCROLLBAR_BUTTON_LEFT || aWidgetType == NS_THEME_SCROLLBAR_BUTTON_RIGHT)
|
|
|
|
|
aResult->SizeTo(scrollbarWidth+1, scrollbarWidth);
|
|
|
|
|
else
|
|
|
|
|
aResult->SizeTo(scrollbarWidth, scrollbarWidth+1);
|
|
|
|
|
|
2011-09-30 17:20:33 -07:00
|
|
|
|
*aIsOverridable = false;
|
2007-04-10 17:25:11 -07:00
|
|
|
|
break;
|
|
|
|
|
}
|
2009-08-20 07:19:18 -07:00
|
|
|
|
case NS_THEME_RESIZER:
|
|
|
|
|
{
|
|
|
|
|
HIThemeGrowBoxDrawInfo drawInfo;
|
|
|
|
|
drawInfo.version = 0;
|
|
|
|
|
drawInfo.state = kThemeStateActive;
|
|
|
|
|
drawInfo.kind = kHIThemeGrowBoxKindNormal;
|
|
|
|
|
drawInfo.direction = kThemeGrowRight | kThemeGrowDown;
|
|
|
|
|
drawInfo.size = kHIThemeGrowBoxSizeNormal;
|
|
|
|
|
HIPoint pnt = { 0, 0 };
|
|
|
|
|
HIRect bounds;
|
|
|
|
|
HIThemeGetGrowBoxBounds(&pnt, &drawInfo, &bounds);
|
|
|
|
|
aResult->SizeTo(bounds.size.width, bounds.size.height);
|
2011-09-30 17:20:33 -07:00
|
|
|
|
*aIsOverridable = false;
|
2009-08-20 07:19:18 -07:00
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
}
|
|
|
|
|
|
2014-06-27 02:19:00 -07:00
|
|
|
|
if (IsHiDPIContext(aPresContext)) {
|
2012-08-13 09:45:57 -07:00
|
|
|
|
*aResult = *aResult * 2;
|
|
|
|
|
}
|
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
|
return NS_OK;
|
2008-02-20 17:01:27 -08:00
|
|
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
|
nsNativeThemeCocoa::WidgetStateChanged(nsIFrame* aFrame, uint8_t aWidgetType,
|
2011-09-28 23:19:26 -07:00
|
|
|
|
nsIAtom* aAttribute, bool* aShouldRepaint)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
{
|
|
|
|
|
// Some widget types just never change state.
|
|
|
|
|
switch (aWidgetType) {
|
2013-10-24 01:07:35 -07:00
|
|
|
|
case NS_THEME_WINDOW_TITLEBAR:
|
2007-03-22 10:30:00 -07:00
|
|
|
|
case NS_THEME_TOOLBOX:
|
|
|
|
|
case NS_THEME_TOOLBAR:
|
2008-09-16 01:21:06 -07:00
|
|
|
|
case NS_THEME_MOZ_MAC_UNIFIED_TOOLBAR:
|
2007-03-22 10:30:00 -07:00
|
|
|
|
case NS_THEME_STATUSBAR:
|
|
|
|
|
case NS_THEME_STATUSBAR_PANEL:
|
|
|
|
|
case NS_THEME_STATUSBAR_RESIZER_PANEL:
|
|
|
|
|
case NS_THEME_TOOLTIP:
|
|
|
|
|
case NS_THEME_TAB_PANELS:
|
|
|
|
|
case NS_THEME_TAB_PANEL:
|
|
|
|
|
case NS_THEME_DIALOG:
|
|
|
|
|
case NS_THEME_MENUPOPUP:
|
2008-03-13 13:24:29 -07:00
|
|
|
|
case NS_THEME_GROUPBOX:
|
2008-04-07 15:56:43 -07:00
|
|
|
|
case NS_THEME_PROGRESSBAR_CHUNK:
|
|
|
|
|
case NS_THEME_PROGRESSBAR_CHUNK_VERTICAL:
|
|
|
|
|
case NS_THEME_PROGRESSBAR:
|
|
|
|
|
case NS_THEME_PROGRESSBAR_VERTICAL:
|
2012-06-06 00:56:28 -07:00
|
|
|
|
case NS_THEME_METERBAR:
|
|
|
|
|
case NS_THEME_METERBAR_CHUNK:
|
2011-09-30 17:20:33 -07:00
|
|
|
|
*aShouldRepaint = false;
|
2008-04-07 15:56:43 -07:00
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// XXXdwh Not sure what can really be done here. Can at least guess for
|
|
|
|
|
// specific widgets that they're highly unlikely to have certain states.
|
|
|
|
|
// For example, a toolbar doesn't care about any states.
|
|
|
|
|
if (!aAttribute) {
|
|
|
|
|
// Hover/focus/active changed. Always repaint.
|
2011-09-30 17:20:33 -07:00
|
|
|
|
*aShouldRepaint = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
} else {
|
|
|
|
|
// Check the attribute to see if it's relevant.
|
|
|
|
|
// disabled, checked, dlgtype, default, etc.
|
2011-09-30 17:20:33 -07:00
|
|
|
|
*aShouldRepaint = false;
|
2011-10-14 11:11:22 -07:00
|
|
|
|
if (aAttribute == nsGkAtoms::disabled ||
|
|
|
|
|
aAttribute == nsGkAtoms::checked ||
|
|
|
|
|
aAttribute == nsGkAtoms::selected ||
|
|
|
|
|
aAttribute == nsGkAtoms::menuactive ||
|
|
|
|
|
aAttribute == nsGkAtoms::sortDirection ||
|
|
|
|
|
aAttribute == nsGkAtoms::focused ||
|
|
|
|
|
aAttribute == nsGkAtoms::_default ||
|
2013-05-02 07:58:00 -07:00
|
|
|
|
aAttribute == nsGkAtoms::open ||
|
|
|
|
|
aAttribute == nsGkAtoms::hover)
|
2011-09-30 17:20:33 -07:00
|
|
|
|
*aShouldRepaint = true;
|
2014-05-28 03:52:13 -07:00
|
|
|
|
|
|
|
|
|
if ((aWidgetType == NS_THEME_SCROLLBAR ||
|
|
|
|
|
aWidgetType == NS_THEME_SCROLLBAR_SMALL) &&
|
2014-05-28 06:22:16 -07:00
|
|
|
|
!ScrollbarTrackAndThumbDrawSeparately() &&
|
2014-05-28 03:52:13 -07:00
|
|
|
|
(aAttribute == nsGkAtoms::curpos ||
|
|
|
|
|
aAttribute == nsGkAtoms::minpos ||
|
|
|
|
|
aAttribute == nsGkAtoms::maxpos ||
|
|
|
|
|
aAttribute == nsGkAtoms::pageincrement)) {
|
2014-05-28 06:22:16 -07:00
|
|
|
|
// 10.6-style scrollbars paint the thumb as part of the scrollbar,
|
2014-05-28 03:52:13 -07:00
|
|
|
|
// so we need to invalidate the scrollbar when the thumb moves.
|
|
|
|
|
*aShouldRepaint = true;
|
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
|
nsNativeThemeCocoa::ThemeChanged()
|
|
|
|
|
{
|
|
|
|
|
// This is unimplemented because we don't care if gecko changes its theme
|
|
|
|
|
// and Mac OS X doesn't have themes.
|
|
|
|
|
return NS_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
|
bool
|
2007-03-22 10:30:00 -07:00
|
|
|
|
nsNativeThemeCocoa::ThemeSupportsWidget(nsPresContext* aPresContext, nsIFrame* aFrame,
|
2012-08-22 08:56:38 -07:00
|
|
|
|
uint8_t aWidgetType)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
{
|
2008-11-13 08:52:32 -08:00
|
|
|
|
// We don't have CSS set up to render non-native scrollbars on Mac OS X so we
|
|
|
|
|
// render natively even if native theme support is disabled.
|
|
|
|
|
if (aWidgetType != NS_THEME_SCROLLBAR &&
|
|
|
|
|
aPresContext && !aPresContext->PresShell()->IsThemeSupportEnabled())
|
2011-09-30 17:20:33 -07:00
|
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
2007-08-27 20:39:19 -07:00
|
|
|
|
// if this is a dropdown button in a combobox the answer is always no
|
|
|
|
|
if (aWidgetType == NS_THEME_DROPDOWN_BUTTON) {
|
|
|
|
|
nsIFrame* parentFrame = aFrame->GetParent();
|
2011-10-14 11:11:22 -07:00
|
|
|
|
if (parentFrame && (parentFrame->GetType() == nsGkAtoms::comboboxControlFrame))
|
2011-09-30 17:20:33 -07:00
|
|
|
|
return false;
|
2007-08-27 20:39:19 -07:00
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
|
|
switch (aWidgetType) {
|
2007-08-27 20:39:19 -07:00
|
|
|
|
case NS_THEME_LISTBOX:
|
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
|
case NS_THEME_DIALOG:
|
|
|
|
|
case NS_THEME_WINDOW:
|
2013-05-02 11:15:29 -07:00
|
|
|
|
case NS_THEME_WINDOW_BUTTON_BOX:
|
2013-05-22 02:48:47 -07:00
|
|
|
|
case NS_THEME_WINDOW_TITLEBAR:
|
2014-07-04 11:02:44 -07:00
|
|
|
|
case NS_THEME_CHECKMENUITEM:
|
2007-03-22 10:30:00 -07:00
|
|
|
|
case NS_THEME_MENUPOPUP:
|
2014-09-08 02:45:00 -07:00
|
|
|
|
case NS_THEME_MENUARROW:
|
2007-03-22 10:30:00 -07:00
|
|
|
|
case NS_THEME_MENUITEM:
|
2008-02-24 05:41:22 -08:00
|
|
|
|
case NS_THEME_MENUSEPARATOR:
|
2013-05-02 11:15:29 -07:00
|
|
|
|
case NS_THEME_MOZ_MAC_FULLSCREEN_BUTTON:
|
2007-03-22 10:30:00 -07:00
|
|
|
|
case NS_THEME_TOOLTIP:
|
|
|
|
|
|
|
|
|
|
case NS_THEME_CHECKBOX:
|
|
|
|
|
case NS_THEME_CHECKBOX_CONTAINER:
|
|
|
|
|
case NS_THEME_RADIO:
|
|
|
|
|
case NS_THEME_RADIO_CONTAINER:
|
2008-03-13 13:24:29 -07:00
|
|
|
|
case NS_THEME_GROUPBOX:
|
2014-02-27 09:12:16 -08:00
|
|
|
|
case NS_THEME_MOZ_MAC_HELP_BUTTON:
|
2007-03-22 10:30:00 -07:00
|
|
|
|
case NS_THEME_BUTTON:
|
2014-09-08 02:45:00 -07:00
|
|
|
|
case NS_THEME_BUTTON_ARROW_UP:
|
|
|
|
|
case NS_THEME_BUTTON_ARROW_DOWN:
|
2007-03-22 10:30:00 -07:00
|
|
|
|
case NS_THEME_BUTTON_BEVEL:
|
2011-08-08 07:42:45 -07:00
|
|
|
|
case NS_THEME_TOOLBAR_BUTTON:
|
2007-03-22 10:30:00 -07:00
|
|
|
|
case NS_THEME_SPINNER:
|
2013-12-05 08:20:34 -08:00
|
|
|
|
case NS_THEME_SPINNER_UP_BUTTON:
|
|
|
|
|
case NS_THEME_SPINNER_DOWN_BUTTON:
|
2007-03-22 10:30:00 -07:00
|
|
|
|
case NS_THEME_TOOLBAR:
|
2008-09-16 01:21:06 -07:00
|
|
|
|
case NS_THEME_MOZ_MAC_UNIFIED_TOOLBAR:
|
2007-03-22 10:30:00 -07:00
|
|
|
|
case NS_THEME_STATUSBAR:
|
2013-12-08 15:23:28 -08:00
|
|
|
|
case NS_THEME_NUMBER_INPUT:
|
2007-03-22 10:30:00 -07:00
|
|
|
|
case NS_THEME_TEXTFIELD:
|
2007-05-06 19:06:58 -07:00
|
|
|
|
case NS_THEME_TEXTFIELD_MULTILINE:
|
2008-12-06 03:40:58 -08:00
|
|
|
|
case NS_THEME_SEARCHFIELD:
|
2007-03-22 10:30:00 -07:00
|
|
|
|
//case NS_THEME_TOOLBOX:
|
|
|
|
|
//case NS_THEME_TOOLBAR_BUTTON:
|
|
|
|
|
case NS_THEME_PROGRESSBAR:
|
|
|
|
|
case NS_THEME_PROGRESSBAR_VERTICAL:
|
|
|
|
|
case NS_THEME_PROGRESSBAR_CHUNK:
|
|
|
|
|
case NS_THEME_PROGRESSBAR_CHUNK_VERTICAL:
|
2012-06-06 00:56:28 -07:00
|
|
|
|
case NS_THEME_METERBAR:
|
|
|
|
|
case NS_THEME_METERBAR_CHUNK:
|
2007-03-22 10:30:00 -07:00
|
|
|
|
case NS_THEME_TOOLBAR_SEPARATOR:
|
|
|
|
|
|
|
|
|
|
case NS_THEME_TAB_PANELS:
|
|
|
|
|
case NS_THEME_TAB:
|
|
|
|
|
|
|
|
|
|
case NS_THEME_TREEVIEW_TWISTY:
|
|
|
|
|
case NS_THEME_TREEVIEW_TWISTY_OPEN:
|
|
|
|
|
case NS_THEME_TREEVIEW:
|
|
|
|
|
case NS_THEME_TREEVIEW_HEADER:
|
|
|
|
|
case NS_THEME_TREEVIEW_HEADER_CELL:
|
|
|
|
|
case NS_THEME_TREEVIEW_HEADER_SORTARROW:
|
|
|
|
|
case NS_THEME_TREEVIEW_TREEITEM:
|
|
|
|
|
case NS_THEME_TREEVIEW_LINE:
|
|
|
|
|
|
2013-03-15 22:40:15 -07:00
|
|
|
|
case NS_THEME_RANGE:
|
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
|
case NS_THEME_SCALE_HORIZONTAL:
|
|
|
|
|
case NS_THEME_SCALE_THUMB_HORIZONTAL:
|
|
|
|
|
case NS_THEME_SCALE_VERTICAL:
|
|
|
|
|
case NS_THEME_SCALE_THUMB_VERTICAL:
|
|
|
|
|
|
|
|
|
|
case NS_THEME_SCROLLBAR:
|
|
|
|
|
case NS_THEME_SCROLLBAR_SMALL:
|
|
|
|
|
case NS_THEME_SCROLLBAR_BUTTON_UP:
|
|
|
|
|
case NS_THEME_SCROLLBAR_BUTTON_DOWN:
|
|
|
|
|
case NS_THEME_SCROLLBAR_BUTTON_LEFT:
|
|
|
|
|
case NS_THEME_SCROLLBAR_BUTTON_RIGHT:
|
|
|
|
|
case NS_THEME_SCROLLBAR_THUMB_HORIZONTAL:
|
|
|
|
|
case NS_THEME_SCROLLBAR_THUMB_VERTICAL:
|
|
|
|
|
case NS_THEME_SCROLLBAR_TRACK_VERTICAL:
|
|
|
|
|
case NS_THEME_SCROLLBAR_TRACK_HORIZONTAL:
|
2013-05-26 15:05:10 -07:00
|
|
|
|
case NS_THEME_SCROLLBAR_NON_DISAPPEARING:
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
|
|
case NS_THEME_DROPDOWN:
|
|
|
|
|
case NS_THEME_DROPDOWN_BUTTON:
|
|
|
|
|
case NS_THEME_DROPDOWN_TEXT:
|
2009-02-11 07:54:10 -08:00
|
|
|
|
case NS_THEME_DROPDOWN_TEXTFIELD:
|
2007-08-27 20:39:19 -07:00
|
|
|
|
return !IsWidgetStyled(aPresContext, aFrame, aWidgetType);
|
|
|
|
|
break;
|
2010-06-21 05:37:35 -07:00
|
|
|
|
|
|
|
|
|
case NS_THEME_RESIZER:
|
|
|
|
|
{
|
|
|
|
|
nsIFrame* parentFrame = aFrame->GetParent();
|
2011-10-14 11:11:22 -07:00
|
|
|
|
if (!parentFrame || parentFrame->GetType() != nsGkAtoms::scrollFrame)
|
2011-09-30 17:20:33 -07:00
|
|
|
|
return true;
|
2010-06-21 05:37:35 -07:00
|
|
|
|
|
|
|
|
|
// Note that IsWidgetStyled is not called for resizers on Mac. This is
|
|
|
|
|
// because for scrollable containers, the native resizer looks better
|
2013-05-02 07:58:00 -07:00
|
|
|
|
// when (non-overlay) scrollbars are present even when the style is
|
|
|
|
|
// overriden, and the custom transparent resizer looks better when
|
|
|
|
|
// scrollbars are not present.
|
2010-06-21 05:37:35 -07:00
|
|
|
|
nsIScrollableFrame* scrollFrame = do_QueryFrame(parentFrame);
|
2013-06-07 12:44:24 -07:00
|
|
|
|
return (!nsLookAndFeel::UseOverlayScrollbars() &&
|
2013-05-02 07:58:00 -07:00
|
|
|
|
scrollFrame && scrollFrame->GetScrollbarVisibility());
|
2010-06-21 05:37:35 -07:00
|
|
|
|
break;
|
|
|
|
|
}
|
2014-06-14 05:48:08 -07:00
|
|
|
|
case NS_THEME_FOCUS_OUTLINE:
|
|
|
|
|
return true;
|
2014-08-27 17:15:33 -07:00
|
|
|
|
|
|
|
|
|
case NS_THEME_MAC_VIBRANCY_LIGHT:
|
|
|
|
|
case NS_THEME_MAC_VIBRANCY_DARK:
|
|
|
|
|
return VibrancyManager::SystemSupportsVibrancy();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
}
|
|
|
|
|
|
2011-09-30 17:20:33 -07:00
|
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
}
|
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
|
bool
|
2012-08-22 08:56:38 -07:00
|
|
|
|
nsNativeThemeCocoa::WidgetIsContainer(uint8_t aWidgetType)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
{
|
|
|
|
|
// flesh this out at some point
|
|
|
|
|
switch (aWidgetType) {
|
|
|
|
|
case NS_THEME_DROPDOWN_BUTTON:
|
|
|
|
|
case NS_THEME_RADIO:
|
|
|
|
|
case NS_THEME_CHECKBOX:
|
|
|
|
|
case NS_THEME_PROGRESSBAR:
|
2012-06-06 00:56:28 -07:00
|
|
|
|
case NS_THEME_METERBAR:
|
2013-03-15 22:40:15 -07:00
|
|
|
|
case NS_THEME_RANGE:
|
2014-02-27 09:12:16 -08:00
|
|
|
|
case NS_THEME_MOZ_MAC_HELP_BUTTON:
|
2011-09-30 17:20:33 -07:00
|
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
break;
|
|
|
|
|
}
|
2011-09-30 17:20:33 -07:00
|
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
}
|
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
|
bool
|
2013-05-13 16:47:03 -07:00
|
|
|
|
nsNativeThemeCocoa::ThemeDrawsFocusForWidget(uint8_t aWidgetType)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
{
|
|
|
|
|
if (aWidgetType == NS_THEME_DROPDOWN ||
|
2009-02-11 07:54:10 -08:00
|
|
|
|
aWidgetType == NS_THEME_DROPDOWN_TEXTFIELD ||
|
2008-01-13 20:48:33 -08:00
|
|
|
|
aWidgetType == NS_THEME_BUTTON ||
|
2014-02-27 09:12:16 -08:00
|
|
|
|
aWidgetType == NS_THEME_MOZ_MAC_HELP_BUTTON ||
|
2008-01-13 20:48:33 -08:00
|
|
|
|
aWidgetType == NS_THEME_RADIO ||
|
2013-04-17 01:24:46 -07:00
|
|
|
|
aWidgetType == NS_THEME_RANGE ||
|
2008-11-03 05:12:59 -08:00
|
|
|
|
aWidgetType == NS_THEME_CHECKBOX)
|
2011-09-30 17:20:33 -07:00
|
|
|
|
return true;
|
2008-01-13 20:48:33 -08:00
|
|
|
|
|
2011-09-30 17:20:33 -07:00
|
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
}
|
2007-05-17 20:04:04 -07:00
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
|
bool
|
2007-05-17 20:04:04 -07:00
|
|
|
|
nsNativeThemeCocoa::ThemeNeedsComboboxDropmarker()
|
|
|
|
|
{
|
2011-09-30 17:20:33 -07:00
|
|
|
|
return false;
|
2007-05-17 20:04:04 -07:00
|
|
|
|
}
|
2008-12-11 06:37:38 -08:00
|
|
|
|
|
2013-09-27 08:24:32 -07:00
|
|
|
|
bool
|
|
|
|
|
nsNativeThemeCocoa::WidgetAppearanceDependsOnWindowFocus(uint8_t aWidgetType)
|
|
|
|
|
{
|
|
|
|
|
switch (aWidgetType) {
|
|
|
|
|
case NS_THEME_DIALOG:
|
|
|
|
|
case NS_THEME_GROUPBOX:
|
|
|
|
|
case NS_THEME_TAB_PANELS:
|
2014-09-08 02:45:00 -07:00
|
|
|
|
case NS_THEME_BUTTON_ARROW_UP:
|
|
|
|
|
case NS_THEME_BUTTON_ARROW_DOWN:
|
2014-07-04 11:02:44 -07:00
|
|
|
|
case NS_THEME_CHECKMENUITEM:
|
2013-09-27 08:24:32 -07:00
|
|
|
|
case NS_THEME_MENUPOPUP:
|
2014-09-08 02:45:00 -07:00
|
|
|
|
case NS_THEME_MENUARROW:
|
2013-09-27 08:24:32 -07:00
|
|
|
|
case NS_THEME_MENUITEM:
|
|
|
|
|
case NS_THEME_MENUSEPARATOR:
|
|
|
|
|
case NS_THEME_TOOLTIP:
|
|
|
|
|
case NS_THEME_SPINNER:
|
2013-12-05 08:20:34 -08:00
|
|
|
|
case NS_THEME_SPINNER_UP_BUTTON:
|
|
|
|
|
case NS_THEME_SPINNER_DOWN_BUTTON:
|
2013-09-27 08:24:32 -07:00
|
|
|
|
case NS_THEME_TOOLBAR_SEPARATOR:
|
|
|
|
|
case NS_THEME_TOOLBOX:
|
2013-12-08 15:23:28 -08:00
|
|
|
|
case NS_THEME_NUMBER_INPUT:
|
2013-09-27 08:24:32 -07:00
|
|
|
|
case NS_THEME_TEXTFIELD:
|
|
|
|
|
case NS_THEME_TREEVIEW:
|
|
|
|
|
case NS_THEME_TREEVIEW_LINE:
|
|
|
|
|
case NS_THEME_TEXTFIELD_MULTILINE:
|
|
|
|
|
case NS_THEME_LISTBOX:
|
|
|
|
|
case NS_THEME_RESIZER:
|
|
|
|
|
return false;
|
|
|
|
|
default:
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-27 17:15:33 -07:00
|
|
|
|
bool
|
|
|
|
|
nsNativeThemeCocoa::NeedToClearBackgroundBehindWidget(uint8_t aWidgetType)
|
|
|
|
|
{
|
|
|
|
|
switch (aWidgetType) {
|
|
|
|
|
case NS_THEME_MAC_VIBRANCY_LIGHT:
|
|
|
|
|
case NS_THEME_MAC_VIBRANCY_DARK:
|
|
|
|
|
return true;
|
|
|
|
|
default:
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-06-10 15:53:57 -07:00
|
|
|
|
nsITheme::Transparency
|
2012-08-22 08:56:38 -07:00
|
|
|
|
nsNativeThemeCocoa::GetWidgetTransparency(nsIFrame* aFrame, uint8_t aWidgetType)
|
2008-12-11 06:37:38 -08:00
|
|
|
|
{
|
2010-07-15 14:08:03 -07:00
|
|
|
|
switch (aWidgetType) {
|
|
|
|
|
case NS_THEME_MENUPOPUP:
|
|
|
|
|
case NS_THEME_TOOLTIP:
|
2010-06-10 15:53:57 -07:00
|
|
|
|
return eTransparent;
|
2008-12-11 06:37:38 -08:00
|
|
|
|
|
2010-07-15 14:08:03 -07:00
|
|
|
|
case NS_THEME_SCROLLBAR_SMALL:
|
|
|
|
|
case NS_THEME_SCROLLBAR:
|
2013-06-07 12:44:24 -07:00
|
|
|
|
return nsLookAndFeel::UseOverlayScrollbars() ? eTransparent : eOpaque;
|
2013-05-02 07:58:00 -07:00
|
|
|
|
|
2010-08-27 16:15:08 -07:00
|
|
|
|
case NS_THEME_STATUSBAR:
|
|
|
|
|
// Knowing that scrollbars and statusbars are opaque improves
|
|
|
|
|
// performance, because we create layers for them.
|
2010-07-15 14:08:03 -07:00
|
|
|
|
return eOpaque;
|
|
|
|
|
|
2013-11-20 08:20:51 -08:00
|
|
|
|
case NS_THEME_TOOLBAR:
|
|
|
|
|
case NS_THEME_MOZ_MAC_UNIFIED_TOOLBAR:
|
|
|
|
|
return eOpaque;
|
|
|
|
|
|
2010-07-15 14:08:03 -07:00
|
|
|
|
default:
|
|
|
|
|
return eUnknownTransparency;
|
|
|
|
|
}
|
2008-12-11 06:37:38 -08:00
|
|
|
|
}
|