static bool orientationMediaFeatureEval(CSSValueImpl *value, RenderStyle *, KHTMLPart *part, MediaFeaturePrefix /*op*/) { if (value) { CSSPrimitiveValueImpl *pv = static_cast<CSSPrimitiveValueImpl *>(value); if (!value->isPrimitiveValue() || pv->primitiveType() != CSSPrimitiveValue::CSS_IDENT || (pv->getIdent() != CSS_VAL_PORTRAIT && pv->getIdent() != CSS_VAL_LANDSCAPE)) { return false; } KHTMLPart *rootPart = part; while (rootPart->parentPart()) { rootPart = rootPart->parentPart(); } DOM::DocumentImpl *doc = static_cast<DOM::DocumentImpl *>(rootPart->document().handle()); QPaintDevice *pd = doc->paintDevice(); bool printing = pd ? (pd->devType() == QInternal::Printer) : false; if (printing) { if (pd->width() > pd->height()) { return (pv->getIdent() == CSS_VAL_LANDSCAPE); } } else { if (part->view()->visibleWidth() > part->view()->visibleHeight()) { return (pv->getIdent() == CSS_VAL_LANDSCAPE); } } return (pv->getIdent() == CSS_VAL_PORTRAIT); } return false; }
static bool monochromeMediaFeatureEval(CSSValueImpl* value, RenderStyle*, KHTMLPart* part, MediaFeaturePrefix op) { KHTMLPart* rootPart = part; while (rootPart->parentPart()) rootPart = rootPart->parentPart(); DOM::DocumentImpl *doc = static_cast<DOM::DocumentImpl*>(rootPart->document().handle()); QPaintDevice *pd = doc->paintDevice(); bool printing = pd ? (pd->devType() == QInternal::Printer) : false; int depth = 0; if (printing) { if (pd->numColors() < 2) depth = 1; // assume printer is either b&w or color. } else { int sn = QApplication::desktop()->screenNumber( rootPart->view() ); if (QApplication::desktop()->screen(sn)->depth() == 1) depth = 1; else if (QColormap::instance(sn).mode() == QColormap::Gray) depth = QApplication::desktop()->screen(sn)->depth(); } if (value) { float number = 0; return numberValue(value, number) && compareValue(depth, static_cast<int>(number), op); } return depth; }
static bool aspect_ratioMediaFeatureEval(CSSValueImpl *value, RenderStyle *, KHTMLPart *part, MediaFeaturePrefix op) { if (value) { KHTMLPart *rootPart = part; while (rootPart->parentPart()) { rootPart = rootPart->parentPart(); } DOM::DocumentImpl *doc = static_cast<DOM::DocumentImpl *>(rootPart->document().handle()); QPaintDevice *pd = doc->paintDevice(); bool printing = pd ? (pd->devType() == QInternal::Printer) : false; QSize vs; int h = 0, v = 0; if (printing) { vs = QSize(pd->width(), pd->height()); } else { vs = QSize(part->view()->visibleWidth(), part->view()->visibleHeight()); } if (parseAspectRatio(value, h, v)) { return v != 0 && compareValue(vs.width() * v, vs.height() * h, op); } return false; } // ({,min-,max-}aspect-ratio) // assume if we have a viewport, its aspect ratio is non-zero return true; }
static bool device_aspect_ratioMediaFeatureEval(CSSValueImpl *value, RenderStyle *, KHTMLPart *part, MediaFeaturePrefix op) { if (value) { KHTMLPart *rootPart = part; while (rootPart->parentPart()) { rootPart = rootPart->parentPart(); } DOM::DocumentImpl *doc = static_cast<DOM::DocumentImpl *>(rootPart->document().handle()); QPaintDevice *pd = doc->paintDevice(); bool printing = pd ? (pd->devType() == QInternal::Printer) : false; QRect sg; int h = 0, v = 0; if (printing) { sg = QRect(0, 0, pd->width(), pd->height()); } else { sg = QApplication::desktop()->screen(QApplication::desktop()->screenNumber(rootPart->view()))->rect(); } if (parseAspectRatio(value, h, v)) { return v != 0 && compareValue(sg.width() * v, sg.height() * h, op); } return false; } // ({,min-,max-}device-aspect-ratio) // assume if we have a device, its aspect ratio is non-zero return true; }
static bool colorMediaFeatureEval(CSSValueImpl *value, RenderStyle *, KHTMLPart *part, MediaFeaturePrefix op) { KHTMLPart *rootPart = part; while (rootPart->parentPart()) { rootPart = rootPart->parentPart(); } DOM::DocumentImpl *doc = static_cast<DOM::DocumentImpl *>(rootPart->document().handle()); QPaintDevice *pd = doc->paintDevice(); bool printing = pd ? (pd->devType() == QInternal::Printer) : false; int bitsPerComponent = 0; if (printing) { if (pd->colorCount() > 2) { bitsPerComponent = pd->depth() / 3; } // assume printer is either b&w or color. } else { int sn = QApplication::desktop()->screenNumber(rootPart->view()); if (QColormap::instance(sn).mode() != QColormap::Gray) { bitsPerComponent = QApplication::desktop()->screen(sn)->depth() / 3; } } if (value && bitsPerComponent) { float number = 0; return numberValue(value, number) && compareValue(bitsPerComponent, static_cast<int>(number), op); } return bitsPerComponent; }
static bool color_indexMediaFeatureEval(CSSValueImpl *value, RenderStyle *, KHTMLPart *part, MediaFeaturePrefix op) { KHTMLPart *rootPart = part; while (rootPart->parentPart()) { rootPart = rootPart->parentPart(); } DOM::DocumentImpl *doc = static_cast<DOM::DocumentImpl *>(rootPart->document().handle()); QPaintDevice *pd = doc->paintDevice(); bool printing = pd ? (pd->devType() == QInternal::Printer) : false; unsigned int numColors = 0; if (printing) { numColors = pd->colorCount(); } else { int sn = QApplication::desktop()->screenNumber(rootPart->view()); numColors = QApplication::desktop()->screen(sn)->colorCount(); } if (numColors == INT_MAX) { numColors = UINT_MAX; } if (value) { float number = 0; return numberValue(value, number) && compareValue(numColors, static_cast<unsigned int>(number), op); } return numColors; }
static bool heightMediaFeatureEval(CSSValueImpl* value, RenderStyle* style, KHTMLPart* part, MediaFeaturePrefix op) { KHTMLPart* rootPart = part; while (rootPart->parentPart()) rootPart = rootPart->parentPart(); DOM::DocumentImpl *doc = static_cast<DOM::DocumentImpl*>(rootPart->document().handle()); QPaintDevice *pd = doc->paintDevice(); bool printing = pd ? (pd->devType() == QInternal::Printer) : false; int height; if (printing) height = pd->height(); else { height = part->view()->visibleHeight(); doc = static_cast<DOM::DocumentImpl*>(part->document().handle()); } int logicalDpiY = doc->logicalDpiY(); if (value) return value->isPrimitiveValue() && compareValue(height, static_cast<CSSPrimitiveValueImpl*>(value)->computeLength(style, logicalDpiY), op); return height > 0; }
static bool device_widthMediaFeatureEval(CSSValueImpl* value, RenderStyle* style, KHTMLPart* part, MediaFeaturePrefix op) { if (value) { KHTMLPart* rootPart = part; while (rootPart->parentPart()) rootPart = rootPart->parentPart(); DOM::DocumentImpl *doc = static_cast<DOM::DocumentImpl*>(rootPart->document().handle()); QPaintDevice *pd = doc->paintDevice(); bool printing = pd ? (pd->devType() == QInternal::Printer) : false; int width; if (printing) width = pd->width(); else { width = QApplication::desktop()->screen(QApplication::desktop()->screenNumber( rootPart->view() ))->rect().width(); doc = static_cast<DOM::DocumentImpl*>(part->document().handle()); } int logicalDpiY = doc->logicalDpiY(); return value->isPrimitiveValue() && compareValue(width, static_cast<CSSPrimitiveValueImpl*>(value)->computeLength(style,logicalDpiY), op); } // ({,min-,max-}device-width) // assume if we have a device, assume non-zero return true; }
static bool widthMediaFeatureEval(CSSValueImpl *value, RenderStyle *style, KHTMLPart *part, MediaFeaturePrefix op) { KHTMLPart *rootPart = part; while (rootPart->parentPart()) { rootPart = rootPart->parentPart(); } DOM::DocumentImpl *doc = static_cast<DOM::DocumentImpl *>(rootPart->document().handle()); QPaintDevice *pd = doc->paintDevice(); bool printing = pd ? (pd->devType() == QInternal::Printer) : false; int width; if (printing) { width = pd->width(); } else { width = part->view()->visibleWidth(); doc = static_cast<DOM::DocumentImpl *>(part->document().handle()); } int logicalDpiY = doc->logicalDpiY(); if (value) { return value->isPrimitiveValue() && compareValue(width, static_cast<CSSPrimitiveValueImpl *>(value)->computeLength(style, style, logicalDpiY), op); } return width > 0; }