Submitted by: eseidel
Reviewed by: mjs
* kwq/DOM-CSS.mm:
(-[DOMRGBColor _color]): changed to nsColor()
* kwq/KWQAccObject.mm:
(AXAttributeStringSetStyle): changed to nsColor()
* kwq/KWQColor.h: Added defs for KDOM.
* kwq/KWQColor.mm:
(qRed): like qAlpha, kcanvas required.
(qGreen): like qAlpha, kcanvas required.
(qBlue): like qAlpha, kcanvas required.
(parseHexColor): copied from khtml/css/cssparser.h
(QColor::QColor): QColor(QString), will lookup by hex code.
(nsColor): now plain function, instead of member function. (mjs)
(CGColorFromNSColor): stolen from QPalette.mm
(cgColor): added to support CGColor, like nsColor()
(QColor::getRgbaF): new, for KCanvas, from Qt 4.
* kwq/KWQKHTMLPart.mm:
(KWQKHTMLPart::attributedString): changed to nsColor()
(KWQKHTMLPart::fontAttributesForSelectionStart): nsColor()
(KWQKHTMLPart::bodyBackgroundColor): changed to nsColor()
* kwq/KWQLineEdit.mm:
(QLineEdit::setPalette): changed to nsColor()
* kwq/KWQPainter.mm:
(QPainter::_setColorFromBrush): changed to nsColor()
(QPainter::_setColorFromPen): changed to nsColor()
(QPainter::drawText): changed to nsColor()
(QPainter::drawHighlightForText): changed to nsColor()
(QPainter::drawLineForText): changed to nsColor()
(QPainter::_fillRect): changed to nsColor()
(QPainter::setShadow): changed to cgColor()
(QPainter::drawFocusRing): changed to nsColor()
* kwq/KWQTextEdit.mm:
(QTextEdit::setPalette): changed to nsColor()
* kwq/WebCoreBridge.mm:
(-[WebCoreBridge selectionColor]): changed to nsColor()
This patch ended up larger than intended after discussing
with mjs about adding getCGColor() and getCIColor()
We decided that having separate nsColor(), cgColor() and
ciColor() defined elsewhere, was cleanest.
The rest of the patch is QColor additions for kdom/ksvg/kcanvas.
http://bugzilla.opendarwin.org/show_bug.cgi?id=3829
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@9611
268f45cc-cd09-0410-ab3c-
d52691b4dbfc
+2005-07-07 Eric Seidel <eseidel@apple.com>
+
+ Reviewed by mjs.
+
+ * kwq/DOM-CSS.mm:
+ (-[DOMRGBColor _color]): changed to nsColor()
+ * kwq/KWQAccObject.mm:
+ (AXAttributeStringSetStyle): changed to nsColor()
+ * kwq/KWQColor.h: Added defs for KDOM.
+ * kwq/KWQColor.mm:
+ (qRed): like qAlpha, kcanvas required.
+ (qGreen): like qAlpha, kcanvas required.
+ (qBlue): like qAlpha, kcanvas required.
+ (parseHexColor): copied from khtml/css/cssparser.h
+ (QColor::QColor): QColor(QString), will lookup by hex code.
+ (nsColor): now plain function, instead of member function. (mjs)
+ (CGColorFromNSColor): stolen from QPalette.mm
+ (cgColor): added to support CGColor, like nsColor()
+ (QColor::getRgbaF): new, for KCanvas, from Qt 4.
+ * kwq/KWQKHTMLPart.mm:
+ (KWQKHTMLPart::attributedString): changed to nsColor()
+ (KWQKHTMLPart::fontAttributesForSelectionStart): nsColor()
+ (KWQKHTMLPart::bodyBackgroundColor): changed to nsColor()
+ * kwq/KWQLineEdit.mm:
+ (QLineEdit::setPalette): changed to nsColor()
+ * kwq/KWQPainter.mm:
+ (QPainter::_setColorFromBrush): changed to nsColor()
+ (QPainter::_setColorFromPen): changed to nsColor()
+ (QPainter::drawText): changed to nsColor()
+ (QPainter::drawHighlightForText): changed to nsColor()
+ (QPainter::drawLineForText): changed to nsColor()
+ (QPainter::_fillRect): changed to nsColor()
+ (QPainter::setShadow): changed to cgColor()
+ (QPainter::drawFocusRing): changed to nsColor()
+ * kwq/KWQTextEdit.mm:
+ (QTextEdit::setPalette): changed to nsColor()
+ * kwq/WebCoreBridge.mm:
+ (-[WebCoreBridge selectionColor]): changed to nsColor()
+ This patch ended up larger than intended after discussing
+ with mjs about adding getCGColor() and getCIColor()
+ We decided that having separate nsColor(), cgColor() and
+ ciColor() defined elsewhere, was cleanest.
+ The rest of the patch is QColor additions for kdom/ksvg/kcanvas.
+ http://bugzilla.opendarwin.org/show_bug.cgi?id=3829
+
2005-07-07 Eric Seidel <eseidel@apple.com>
Reviewed by mjs.
- (NSColor *)_color
{
QRgb rgb = reinterpret_cast<QRgb>(_internal);
- return QColor(rgb).getNSColor();
+ return nsColor(QColor(rgb));
}
@end
AXAttributeStringSetFont(attrString, NSAccessibilityFontTextAttribute, style->font().getNSFont(), range);
// set basic colors
- AXAttributeStringSetColor(attrString, NSAccessibilityForegroundColorTextAttribute, style->color().getNSColor(), range);
- AXAttributeStringSetColor(attrString, NSAccessibilityBackgroundColorTextAttribute, style->backgroundColor().getNSColor(), range);
+ AXAttributeStringSetColor(attrString, NSAccessibilityForegroundColorTextAttribute, nsColor(style->color()), range);
+ AXAttributeStringSetColor(attrString, NSAccessibilityBackgroundColorTextAttribute, nsColor(style->backgroundColor()), range);
// set super/sub scripting
EVerticalAlign alignment = style->verticalAlign();
if ((decor & khtml::UNDERLINE) != 0) {
AXAttributeStringSetNumber(attrString, NSAccessibilityUnderlineTextAttribute, [NSNumber numberWithBool:YES], range);
- AXAttributeStringSetColor(attrString, NSAccessibilityUnderlineColorTextAttribute, underline.getNSColor(), range);
+ AXAttributeStringSetColor(attrString, NSAccessibilityUnderlineColorTextAttribute, nsColor(underline), range);
}
if ((decor & khtml::LINE_THROUGH) != 0) {
AXAttributeStringSetNumber(attrString, NSAccessibilityStrikethroughTextAttribute, [NSNumber numberWithBool:YES], range);
- AXAttributeStringSetColor(attrString, NSAccessibilityStrikethroughColorTextAttribute, linethrough.getNSColor(), range);
+ AXAttributeStringSetColor(attrString, NSAccessibilityStrikethroughColorTextAttribute, nsColor(linethrough), range);
}
}
}
class NSColor;
#endif
+typedef struct CGColor *CGColorRef;
+
typedef unsigned int QRgb; // RGBA quadruplet
QRgb qRgb(int r, int g, int b);
QRgb qRgba(int r, int g, int b, int a);
int qAlpha(QRgb rgba);
+int qRed(QRgb rgba);
+int qGreen(QRgb rgba);
+int qBlue(QRgb rgba);
class QColor {
public:
QColor() : color(0), valid(false) { }
QColor(QRgb col) : color(col), valid(true) { }
QColor(int r, int g, int b) : color(qRgb(r, g, b)), valid(true) { }
+ explicit QColor(const QString &);
explicit QColor(const char *);
QString name() const;
QRgb rgb() const { return color & 0xFFFFFFFF; } // Preserve the alpha.
void setRgb(int r, int g, int b) { color = qRgb(r, g, b); valid = true; }
void setRgb(int rgb) { color = rgb; valid = true; /* Alpha may be set. Preserve it. */ }
+ void getRgbaF(float *, float *, float *, float *) const;
void hsv(int *, int *, int *) const;
void setHsv(int h, int s, int v);
friend bool operator==(const QColor &a, const QColor &b);
friend bool operator!=(const QColor &a, const QColor &b);
- NSColor *getNSColor() const;
-
private:
QRgb color;
bool valid : 1;
return a.color != b.color || a.valid != b.valid;
}
+NSColor *nsColor(const QColor &);
+CGColorRef cgColor(const QColor &);
+
#endif
#import "KWQNamespace.h"
#import "KWQString.h"
#import "KWQAssertions.h"
+#import "KWQPainter.h"
// NSColor calls don't throw, so no need to block Cocoa exceptions in this file
return (rgba >> 24) & 0xFF;
}
+int qRed(QRgb rgba)
+{
+ return (rgba >> 16) & 0xFF;
+}
+
+int qGreen(QRgb rgba)
+{
+ return (rgba >> 8) & 0xFF;
+}
+
+int qBlue(QRgb rgba)
+{
+ return rgba & 0xFF;
+}
+
+// copied from khtml/css/cssparser.h
+static inline bool parseHexColor(const QString &name, QRgb &rgb)
+{
+ int len = name.length();
+
+ if ( !len )
+ return false;
+ bool ok;
+
+ if ( len == 3 || len == 6 ) {
+ int val = name.toInt(&ok, 16);
+ if ( ok ) {
+ if (len == 6) {
+ rgb = (0xff << 24) | val;
+ return true;
+ }
+ else if ( len == 3 ) {
+ // #abc converts to #aabbcc according to the specs
+ rgb = (0xff << 24) |
+ (val&0xf00)<<12 | (val&0xf00)<<8 |
+ (val&0xf0)<<8 | (val&0xf0)<<4 |
+ (val&0xf)<<4 | (val&0xf);
+ return true;
+ }
+ }
+ }
+ return false;
+}
+
+QColor::QColor(const QString &name) {
+ if(name.startsWith("#")) {
+ valid = parseHexColor(name.mid(1), color);
+ } else {
+ const Color *foundColor = findColor(name.ascii(), name.length());
+ color = foundColor ? foundColor->RGBValue : 0;
+ color |= 0xFF000000;
+ valid = foundColor;
+ }
+}
+
QColor::QColor(const char *name)
{
- const Color *foundColor = findColor(name, strlen(name));
- color = foundColor ? foundColor->RGBValue : 0;
- color |= 0xFF000000;
- valid = foundColor;
+ if(name[0] == '#') {
+ valid = parseHexColor(QString(name).mid(1), color);
+ } else {
+ const Color *foundColor = findColor(name, strlen(name));
+ color = foundColor ? foundColor->RGBValue : 0;
+ color |= 0xFF000000;
+ valid = foundColor;
+ }
}
QString QColor::name() const
return result;
}
-NSColor *QColor::getNSColor() const
+NSColor *nsColor(const QColor &color)
{
- unsigned c = color & 0xFFFFFFFF;
+ unsigned c = color.rgb();
switch (c) {
case 0: {
// Need this to avoid returning nil because cachedRGBAValues will default to 0.
}
#if COLORMATCH_EVERYTHING
- NSColor *result = [NSColor colorWithCalibratedRed:red() / 255.0
- green:green() / 255.0
- blue:blue() / 255.0
- alpha:qAlpha(color)/255.0];
+ NSColor *result = [NSColor colorWithCalibratedRed:qRed(c) / 255.0
+ green:qGreen(c) / 255.0
+ blue:qBlue(c) / 255.0
+ alpha:qAlpha(c) /255.0];
#else
- NSColor *result = [NSColor colorWithDeviceRed:red() / 255.0
- green:green() / 255.0
- blue:blue() / 255.0
- alpha:qAlpha(color)/255.0];
+ NSColor *result = [NSColor colorWithDeviceRed:qRed(c) / 255.0
+ green:qGreen(c) / 255.0
+ blue:qBlue(c) / 255.0
+ alpha:qAlpha(c) /255.0];
#endif
static int cursor;
}
}
}
+
+static CGColorRef CGColorFromNSColor(NSColor *color)
+{
+ // this needs to always use device colorspace so it can de-calibrate the color for
+ // CGColor to possibly recalibrate it
+ NSColor* deviceColor = [color colorUsingColorSpaceName:NSDeviceRGBColorSpace];
+ float red = [deviceColor redComponent];
+ float green = [deviceColor greenComponent];
+ float blue = [deviceColor blueComponent];
+ float alpha = [deviceColor alphaComponent];
+ const float components[] = { red, green, blue, alpha };
+
+ CGColorSpaceRef colorSpace = QPainter::rgbColorSpace();
+ CGColorRef cgColor = CGColorCreate(colorSpace, components);
+ CGColorSpaceRelease(colorSpace);
+ return cgColor;
+}
+
+CGColorRef cgColor(const QColor &c)
+{
+ // We could directly create a CGColor here, but that would
+ // skip any rgb caching the nsColor method does. A direct
+ // creation should be investigated for a possible performance win.
+ return CGColorFromNSColor(nsColor(c));
+}
+
+void QColor::getRgbaF(float *r, float *g, float *b, float *a) const
+{
+ *r = (float)red() / 255.0;
+ *g = (float)green() / 255.0;
+ *b = (float)blue() / 255.0;
+ *a = (float)alpha() / 255.0;
+}
NSMutableDictionary *attrs = [[NSMutableDictionary alloc] init];
[attrs setObject:font forKey:NSFontAttributeName];
if (style && style->color().isValid() && qAlpha(style->color().rgb()) != 0)
- [attrs setObject:style->color().getNSColor() forKey:NSForegroundColorAttributeName];
+ [attrs setObject:nsColor(style->color()) forKey:NSForegroundColorAttributeName];
if (style && style->backgroundColor().isValid() && qAlpha(style->backgroundColor().rgb()) != 0)
- [attrs setObject:style->backgroundColor().getNSColor() forKey:NSBackgroundColorAttributeName];
+ [attrs setObject:nsColor(style->backgroundColor()) forKey:NSBackgroundColorAttributeName];
if (text.length() > 0) {
hasParagraphBreak = false;
attrs = [[NSMutableDictionary alloc] init];
[attrs setObject:font forKey:NSFontAttributeName];
if (style && style->color().isValid())
- [attrs setObject:style->color().getNSColor() forKey:NSForegroundColorAttributeName];
+ [attrs setObject:nsColor(style->color()) forKey:NSForegroundColorAttributeName];
if (style && style->backgroundColor().isValid())
- [attrs setObject:style->backgroundColor().getNSColor() forKey:NSBackgroundColorAttributeName];
+ [attrs setObject:nsColor(style->backgroundColor()) forKey:NSBackgroundColorAttributeName];
NSAttributedString *partialString = [[NSAttributedString alloc] initWithString:listText.getNSString() attributes:attrs];
[attrs release];
NSMutableDictionary *result = [NSMutableDictionary dictionary];
if (style->backgroundColor().isValid() && style->backgroundColor().alpha() != 0)
- [result setObject:style->backgroundColor().getNSColor() forKey:NSBackgroundColorAttributeName];
+ [result setObject:nsColor(style->backgroundColor()) forKey:NSBackgroundColorAttributeName];
if (style->font().getNSFont())
[result setObject:style->font().getNSFont() forKey:NSFontAttributeName];
if (style->color().isValid() && style->color() != black)
- [result setObject:style->color().getNSColor() forKey:NSForegroundColorAttributeName];
+ [result setObject:nsColor(style->color()) forKey:NSForegroundColorAttributeName];
ShadowData *shadow = style->textShadow();
if (shadow) {
NSShadow *s = [[NSShadow alloc] init];
[s setShadowOffset:NSMakeSize(shadow->x, shadow->y)];
[s setShadowBlurRadius:shadow->blur];
- [s setShadowColor:shadow->color.getNSColor()];
+ [s setShadowColor:nsColor(shadow->color)];
[result setObject:s forKey:NSShadowAttributeName];
}
if (xmlDocImpl() && xmlDocImpl()->body() && xmlDocImpl()->body()->renderer()) {
QColor bgColor = xmlDocImpl()->body()->renderer()->style()->backgroundColor();
if (bgColor.isValid()) {
- return bgColor.getNSColor();
+ return nsColor(bgColor);
}
}
return nil;
// backgrounds on some text fields as described in <rdar://problem/3854383>. Text fields will still not be able to display
// transparent and translucent backgrounds, which will need to be fixed in the future. See <rdar://problem/3865114>.
- [textField setTextColor:palette.foreground().getNSColor()];
+ [textField setTextColor:nsColor(palette.foreground())];
QColor background = palette.background();
if (!background.isValid() || background.alpha() == 0)
background = Qt::white;
- [textField setBackgroundColor:background.getNSColor()];
+ [textField setBackgroundColor:nsColor(background)];
KWQ_UNBLOCK_EXCEPTIONS;
}
QColor focusRingColor;
};
-
-static CGColorRef CGColorFromNSColor(NSColor *color)
-{
- // this needs to always use device colorspace so it can de-calibrate the color for
- // CGColor to possibly recalibrate it
- NSColor* deviceColor = [color colorUsingColorSpaceName:NSDeviceRGBColorSpace];
- float red = [deviceColor redComponent];
- float green = [deviceColor greenComponent];
- float blue = [deviceColor blueComponent];
- float alpha = [deviceColor alphaComponent];
- const float components[] = { red, green, blue, alpha };
-
- CGColorSpaceRef colorSpace = QPainter::rgbColorSpace();
- CGColorRef cgColor = CGColorCreate(colorSpace, components);
- CGColorSpaceRelease(colorSpace);
- return cgColor;
-}
-
QPainter::QPainter() : data(new QPainterPrivate), _isForPrinting(false), _usesInactiveTextBackgroundColor(false), _drawsFocusRing(true)
{
}
void QPainter::_setColorFromBrush()
{
- [data->state.brush.color().getNSColor() set];
+ [nsColor(data->state.brush.color()) set];
}
void QPainter::_setColorFromPen()
{
- [data->state.pen.color().getNSColor() set];
+ [nsColor(data->state.pen.color()) set];
}
// This is only used to draw borders.
WebCoreTextStyle style;
WebCoreInitializeEmptyTextStyle(&style);
- style.textColor = data->state.pen.color().getNSColor();
+ style.textColor = nsColor(data->state.pen.color());
style.families = families;
if (alignmentFlags & Qt::AlignRight)
WebCoreInitializeTextRun(&run, (const UniChar *)str, len, from, to);
WebCoreTextStyle style;
WebCoreInitializeEmptyTextStyle(&style);
- style.textColor = data->state.pen.color().getNSColor();
- style.backgroundColor = backgroundColor.isValid() ? backgroundColor.getNSColor() : nil;
+ style.textColor = nsColor(data->state.pen.color());
+ style.backgroundColor = backgroundColor.isValid() ? nsColor(backgroundColor) : nil;
style.rtl = d == RTL ? true : false;
style.visuallyOrdered = visuallyOrdered;
style.letterSpacing = letterSpacing;
WebCoreInitializeTextRun(&run, (const UniChar *)str, len, from, to);
WebCoreTextStyle style;
WebCoreInitializeEmptyTextStyle(&style);
- style.textColor = data->state.pen.color().getNSColor();
- style.backgroundColor = backgroundColor.isValid() ? backgroundColor.getNSColor() : nil;
+ style.textColor = nsColor(data->state.pen.color());
+ style.backgroundColor = backgroundColor.isValid() ? nsColor(backgroundColor) : nil;
style.rtl = d == RTL ? true : false;
style.visuallyOrdered = visuallyOrdered;
style.letterSpacing = letterSpacing;
drawLineForCharacters: NSMakePoint(x, y)
yOffset:(float)yOffset
width: width
- color:data->state.pen.color().getNSColor()
+ color:nsColor(data->state.pen.color())
thickness:data->state.pen.width()];
}
// A fillRect designed to work around buggy behavior in NSRectFill.
void QPainter::_fillRect(float x, float y, float w, float h, const QColor& col)
{
- [col.getNSColor() set];
+ [nsColor(col) set];
NSRectFillUsingOperation(NSMakeRect(x,y,w,h), NSCompositeSourceOver);
}
if (!color.isValid()) {
CGContextSetShadow(context, CGSizeMake(x,-y), blur); // y is flipped.
} else {
- CGColorRef cgColor = CGColorFromNSColor(color.getNSColor());
+ CGColorRef colorCG = cgColor(color);
CGContextSetShadowWithColor(context,
CGSizeMake(x,-y), // y is flipped.
blur,
- cgColor);
- CGColorRelease(cgColor);
+ colorCG);
+ CGColorRelease(colorCG);
}
}
NSRect bounds = [data->focusRingPath bounds];
if (!NSIsEmptyRect(bounds)) {
int radius = (data->focusRingWidth-1)/2;
- NSColor *color = data->hasFocusRingColor ? data->focusRingColor.getNSColor() : nil;
+ NSColor *color = data->hasFocusRingColor ? nsColor(data->focusRingColor) : nil;
[NSGraphicsContext saveGraphicsState];
[[WebCoreGraphicsBridge sharedBridge] setFocusRingStyle:NSFocusRingOnly radius:radius color:color];
[data->focusRingPath fill];
// as described in <rdar://problem/3854383>. We now call setDrawsBackground:NO when the background color is completely
// transparent. This does not solve the problem for translucent background colors for textareas <rdar://problem/3865161>.
- [textArea setTextColor:palette.foreground().getNSColor()];
+ [textArea setTextColor:nsColor(palette.foreground())];
QColor background = palette.background();
if (!background.isValid())
background = Qt::white;
- [textArea setBackgroundColor:background.getNSColor()];
+ [textArea setBackgroundColor:nsColor(background)];
[textArea setDrawsBackground:background.alpha() != 0];
KWQ_UNBLOCK_EXCEPTIONS;
if (root) {
RenderStyle *pseudoStyle = root->getPseudoStyle(RenderStyle::SELECTION);
if (pseudoStyle && pseudoStyle->backgroundColor().isValid()) {
- return pseudoStyle->backgroundColor().getNSColor();
+ return nsColor(pseudoStyle->backgroundColor());
}
}
return _part->displaysWithFocusAttributes() ? [NSColor selectedTextBackgroundColor] : [NSColor secondarySelectedControlColor];