Esempio n. 1
0
static void
GetDisplayMode(nsIDocument* aDocument, const nsMediaFeature*,
               nsCSSValue& aResult)
{
  nsIDocument* rootDocument = TopDocument(aDocument);

  nsCOMPtr<nsISupports> container = rootDocument->GetContainer();
  if (nsCOMPtr<nsIBaseWindow> baseWindow = do_QueryInterface(container)) {
    nsCOMPtr<nsIWidget> mainWidget;
    baseWindow->GetMainWidget(getter_AddRefs(mainWidget));
    if (mainWidget && mainWidget->SizeMode() == nsSizeMode_Fullscreen) {
      aResult.SetIntValue(NS_STYLE_DISPLAY_MODE_FULLSCREEN, eCSSUnit_Enumerated);
      return;
    }
  }

  static_assert(nsIDocShell::DISPLAY_MODE_BROWSER == NS_STYLE_DISPLAY_MODE_BROWSER &&
                nsIDocShell::DISPLAY_MODE_MINIMAL_UI == NS_STYLE_DISPLAY_MODE_MINIMAL_UI &&
                nsIDocShell::DISPLAY_MODE_STANDALONE == NS_STYLE_DISPLAY_MODE_STANDALONE &&
                nsIDocShell::DISPLAY_MODE_FULLSCREEN == NS_STYLE_DISPLAY_MODE_FULLSCREEN,
                "nsIDocShell display modes must mach nsStyleConsts.h");

  uint32_t displayMode = NS_STYLE_DISPLAY_MODE_BROWSER;
  if (nsIDocShell* docShell = rootDocument->GetDocShell()) {
    docShell->GetDisplayMode(&displayMode);
  }

  aResult.SetIntValue(displayMode, eCSSUnit_Enumerated);
}
static void
GetIsResourceDocument(nsPresContext* aPresContext, const nsMediaFeature*,
                      nsCSSValue& aResult)
{
  nsIDocument* doc = aPresContext->Document();
  aResult.SetIntValue(doc && doc->IsResourceDoc() ? 1 : 0, eCSSUnit_Integer);
}
Esempio n. 3
0
static void
GetIsGlyph(nsIDocument* aDocument, const nsMediaFeature* aFeature,
           nsCSSValue& aResult)
{
  MOZ_ASSERT(aFeature->mReqFlags & nsMediaFeature::eUserAgentAndChromeOnly);
  aResult.SetIntValue(aDocument->IsSVGGlyphsDocument() ? 1 : 0, eCSSUnit_Integer);
}
Esempio n. 4
0
static void
GetSystemMetric(nsIDocument* aDocument, const nsMediaFeature* aFeature,
                nsCSSValue& aResult)
{
  aResult.Reset();

  const bool isAccessibleFromContentPages =
    !(aFeature->mReqFlags & nsMediaFeature::eUserAgentAndChromeOnly);

  MOZ_ASSERT(!isAccessibleFromContentPages ||
             *aFeature->mName == nsGkAtoms::_moz_touch_enabled);

  if (isAccessibleFromContentPages &&
      nsContentUtils::ShouldResistFingerprinting(aDocument)) {
    // If "privacy.resistFingerprinting" is enabled, then we simply don't
    // return any system-backed media feature values. (No spoofed values
    // returned.)
    return;
  }

  MOZ_ASSERT(aFeature->mValueType == nsMediaFeature::eBoolInteger,
             "unexpected type");

  nsAtom* metricAtom = *aFeature->mData.mMetric;
  bool hasMetric = HasSystemMetric(metricAtom);
  aResult.SetIntValue(hasMetric ? 1 : 0, eCSSUnit_Integer);
}
static void
GetTransform3d(nsPresContext* aPresContext, const nsMediaFeature*,
               nsCSSValue& aResult)
{
  // Gecko supports 3d transforms, so this feature is always 1.
  aResult.SetIntValue(1, eCSSUnit_Integer);
}
Esempio n. 6
0
static nsresult
GetIsGlyph(nsPresContext* aPresContext, const nsMediaFeature* aFeature,
          nsCSSValue& aResult)
{
    aResult.SetIntValue(aPresContext->IsGlyph() ? 1 : 0, eCSSUnit_Integer);
    return NS_OK;
}
static void
GetGrid(nsPresContext* aPresContext, const nsMediaFeature*,
        nsCSSValue& aResult)
{
  // Gecko doesn't support grid devices (e.g., ttys), so the 'grid'
  // feature is always 0.
  aResult.SetIntValue(0, eCSSUnit_Integer);
}
static void
GetMonochrome(nsPresContext* aPresContext, const nsMediaFeature*,
              nsCSSValue& aResult)
{
  // For color devices we should return 0.
  // FIXME: On a monochrome device, return the actual color depth, not
  // 0!
  aResult.SetIntValue(0, eCSSUnit_Integer);
}
Esempio n. 9
0
static void
GetDeviceOrientation(nsIDocument* aDocument, const nsMediaFeature*,
                     nsCSSValue& aResult)
{
  nsSize size = GetDeviceSize(aDocument);
  // Per spec, square viewports should be 'portrait'
  int32_t orientation = size.width > size.height
    ? NS_STYLE_ORIENTATION_LANDSCAPE : NS_STYLE_ORIENTATION_PORTRAIT;
  aResult.SetIntValue(orientation, eCSSUnit_Enumerated);
}
Esempio n. 10
0
static nsresult
GetSystemMetric(nsPresContext* aPresContext, const nsMediaFeature* aFeature,
                nsCSSValue& aResult)
{
    NS_ABORT_IF_FALSE(aFeature->mValueType == nsMediaFeature::eBoolInteger,
                      "unexpected type");
    nsIAtom *metricAtom = *aFeature->mData.mMetric;
    bool hasMetric = nsCSSRuleProcessor::HasSystemMetric(metricAtom);
    aResult.SetIntValue(hasMetric ? 1 : 0, eCSSUnit_Integer);
    return NS_OK;
}
Esempio n. 11
0
static void
GetColorIndex(nsPresContext* aPresContext, const nsMediaFeature*,
              nsCSSValue& aResult)
{
  // We should return zero if the device does not use a color lookup
  // table.  Stuart says that our handling of displays with 8-bit
  // color is bad enough that we never change the lookup table to
  // match what we're trying to display, so perhaps we should always
  // return zero.  Given that there isn't any better information
  // exposed, we don't have much other choice.
  aResult.SetIntValue(0, eCSSUnit_Integer);
}
Esempio n. 12
0
static void
GetDeviceOrientation(nsPresContext* aPresContext, const nsMediaFeature*,
                     nsCSSValue& aResult)
{
  nsSize size = GetDeviceSize(aPresContext);
  int32_t orientation;
  if (size.width > size.height) {
    orientation = NS_STYLE_ORIENTATION_LANDSCAPE;
  } else {
    // Per spec, square viewports should be 'portrait'
    orientation = NS_STYLE_ORIENTATION_PORTRAIT;
  }

  aResult.SetIntValue(orientation, eCSSUnit_Enumerated);
}
Esempio n. 13
0
static void
GetDisplayMode(nsPresContext* aPresContext, const nsMediaFeature*,
               nsCSSValue& aResult)
{
  nsCOMPtr<nsISupports> container;
  if (aPresContext) {
    // Calling GetRootPresContext() can be slow, so make sure to call it
    // just once.
    nsRootPresContext* root = aPresContext->GetRootPresContext();
    if (root && root->Document()) {
      container = root->Document()->GetContainer();
    }
  }
  nsCOMPtr<nsIBaseWindow> baseWindow = do_QueryInterface(container);
  if (!baseWindow) {
    aResult.SetIntValue(NS_STYLE_DISPLAY_MODE_BROWSER, eCSSUnit_Enumerated);
    return;
  }
  nsCOMPtr<nsIWidget> mainWidget;
  baseWindow->GetMainWidget(getter_AddRefs(mainWidget));
  int32_t displayMode;
  nsSizeMode mode = mainWidget ? mainWidget->SizeMode() : nsSizeMode_Normal;
  // Background tabs are always in 'browser' mode for now.
  // If new modes are supported, please ensure not cause the regression in
  // Bug 1259641.
  switch (mode) {
    case nsSizeMode_Fullscreen:
      displayMode = NS_STYLE_DISPLAY_MODE_FULLSCREEN;
      break;
    default:
      displayMode = NS_STYLE_DISPLAY_MODE_BROWSER;
      break;
  }

  aResult.SetIntValue(displayMode, eCSSUnit_Enumerated);
}
Esempio n. 14
0
static void
GetSystemMetric(nsPresContext* aPresContext, const nsMediaFeature* aFeature,
                nsCSSValue& aResult)
{
  aResult.Reset();
  if (ShouldResistFingerprinting(aPresContext)) {
    // If "privacy.resistFingerprinting" is enabled, then we simply don't
    // return any system-backed media feature values. (No spoofed values returned.)
    return;
  }

  MOZ_ASSERT(aFeature->mValueType == nsMediaFeature::eBoolInteger,
             "unexpected type");
  nsIAtom *metricAtom = *aFeature->mData.mMetric;
  bool hasMetric = nsCSSRuleProcessor::HasSystemMetric(metricAtom);
  aResult.SetIntValue(hasMetric ? 1 : 0, eCSSUnit_Integer);
}
Esempio n. 15
0
static nsresult
GetColor(nsPresContext* aPresContext, const nsMediaFeature*,
         nsCSSValue& aResult)
{
    // FIXME:  This implementation is bogus.  nsDeviceContext
    // doesn't provide reliable information (should be fixed in bug
    // 424386).
    // FIXME: On a monochrome device, return 0!
    nsDeviceContext *dx = GetDeviceContextFor(aPresContext);
    uint32_t depth;
    dx->GetDepth(depth);
    // The spec says to use bits *per color component*, so divide by 3,
    // and round down, since the spec says to use the smallest when the
    // color components differ.
    depth /= 3;
    aResult.SetIntValue(int32_t(depth), eCSSUnit_Integer);
    return NS_OK;
}
Esempio n. 16
0
static void
GetColor(nsIDocument* aDocument, const nsMediaFeature*,
         nsCSSValue& aResult)
{
  // Use depth of 24 when resisting fingerprinting, or when we're not being
  // rendered.
  uint32_t depth = 24;

  if (!nsContentUtils::ShouldResistFingerprinting(aDocument)) {
    if (nsDeviceContext* dx = GetDeviceContextFor(aDocument)) {
      // FIXME: On a monochrome device, return 0!
      dx->GetDepth(depth);
    }
  }

  // The spec says to use bits *per color component*, so divide by 3,
  // and round down, since the spec says to use the smallest when the
  // color components differ.
  depth /= 3;
  aResult.SetIntValue(int32_t(depth), eCSSUnit_Integer);
}
Esempio n. 17
0
static void
GetIsResourceDocument(nsIDocument* aDocument, const nsMediaFeature*,
                      nsCSSValue& aResult)
{
  aResult.SetIntValue(aDocument->IsResourceDoc() ? 1 : 0, eCSSUnit_Integer);
}