/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* 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/. */
void TextAttrsMgr::GetAttributes(AccAttributes* aAttributes) {
MOZ_ASSERT( // 1. Hyper text accessible and attributes list must always be specified.
mHyperTextAcc && aAttributes &&
( // 2. If text attributes for a child of a container are being // requested, the offset accessible must be specified and it must // be text.
(mOffsetAcc && mOffsetAcc->IsText()) || // 3. If only default text attributes for a container are being // requested, the offset accessible must not be specified, but the // include default text attributes flag must be specified.
(!mOffsetAcc && mIncludeDefAttrs)), "Wrong usage of TextAttrsMgr!");
// Get the content and frame of the accessible. In the case of document // accessible it's role content and root frame.
nsIContent* hyperTextElm = mHyperTextAcc->GetContent(); if (!hyperTextElm) { return; // XXX: we don't support text attrs on document with no body
}
nsIFrame* rootFrame = mHyperTextAcc->GetFrame(); if (!rootFrame) { return;
}
nsIContent *offsetNode = nullptr, *offsetElm = nullptr;
nsIFrame* frame = nullptr; if (mOffsetAcc) {
offsetNode = mOffsetAcc->GetContent();
offsetElm = nsCoreUtils::GetDOMElementFor(offsetNode);
MOZ_ASSERT(offsetElm, "No element for offset accessible!"); if (!offsetElm) return;
frame = offsetElm->GetPrimaryFrame();
}
// "language" text attribute
LangTextAttr langTextAttr(mHyperTextAcc, hyperTextElm, offsetNode);
// "aria-invalid" text attribute
InvalidTextAttr invalidTextAttr(hyperTextElm, offsetNode);
// "background-color" text attribute
BGColorTextAttr bgColorTextAttr(rootFrame, frame);
// "color" text attribute
ColorTextAttr colorTextAttr(rootFrame, frame);
// "font-family" text attribute
FontFamilyTextAttr fontFamilyTextAttr(rootFrame, frame);
// "font-size" text attribute
FontSizeTextAttr fontSizeTextAttr(rootFrame, frame);
// "font-style" text attribute
FontStyleTextAttr fontStyleTextAttr(rootFrame, frame);
// "font-weight" text attribute
FontWeightTextAttr fontWeightTextAttr(rootFrame, frame);
// "auto-generated" text attribute
AutoGeneratedTextAttr autoGenTextAttr(mHyperTextAcc, mOffsetAcc);
// "text-underline(line-through)-style(color)" text attributes
TextDecorTextAttr textDecorTextAttr(rootFrame, frame);
// "text-position" text attribute
TextPosTextAttr textPosTextAttr(rootFrame, frame, hyperTextElm, offsetNode);
// Each frame of parents chain for the initially passed 'aFrame' has // transparent background color. So background color isn't changed from // 'mRootFrame' to initially passed 'aFrame'. if (parentFrame == mRootFrame) returnfalse;
void TextAttrsMgr::FontSizeTextAttr::ExposeValue(AccAttributes* aAttributes, const nscoord& aValue) { // Convert from nscoord to pt. // // Note: according to IA2, "The conversion doesn't have to be exact. // The intent is to give the user a feel for the size of the text." // // ATK does not specify a unit and will likely follow IA2 here. // // XXX todo: consider sharing this code with layout module? (bug 474621) float px = NSAppUnitsToFloatPixels(aValue, mozilla::AppUnitsPerCSSPixel()); // Each pt is 4/3 of a CSS pixel.
FontSize fontSize{NS_lround(px * 3 / 4)};
void TextAttrsMgr::FontWeightTextAttr::ExposeValue(AccAttributes* aAttributes, const FontWeight& aValue) { int value = aValue.ToIntRounded();
aAttributes->SetAttribute(nsGkAtoms::fontWeight, value);
}
FontWeight TextAttrsMgr::FontWeightTextAttr::GetFontWeight(nsIFrame* aFrame) { // nsFont::width isn't suitable here because it's necessary to expose real // value of font weight (used font might not have some font weight values).
RefPtr<nsFontMetrics> fm =
nsLayoutUtils::GetFontMetricsForFrame(aFrame, 1.0f);
gfxFontGroup* fontGroup = fm->GetThebesFontGroup();
RefPtr<gfxFont> font = fontGroup->GetFirstValidFont();
// When there doesn't exist a bold font in the family and so the rendering of // a non-bold font face is changed so that the user sees what looks like a // bold font, i.e. synthetic bolding is used. (Simply returns false on any // platforms that don't use the multi-strike synthetic bolding.) if (font->ApplySyntheticBold()) { return FontWeight::BOLD;
}
// On Windows, font->GetStyle()->weight will give the same weight as // fontEntry->Weight(), the weight of the first font in the font group, // which may not be the weight of the font face used to render the // characters. On Mac, font->GetStyle()->weight will just give the same // number as getComputedStyle(). fontEntry->Weight() will give the weight // range supported by the font face used, so we clamp the weight that was // requested by style to what is actually supported by the font.
gfxFontEntry* fontEntry = font->GetFontEntry(); return fontEntry->Weight().Clamp(font->GetStyle()->weight);
}
TextAttrsMgr::TextPosTextAttr::TextPosTextAttr(nsIFrame* aRootFrame,
nsIFrame* aFrame,
nsIContent* aRootElm,
nsIContent* aElm)
: TTextAttr<Maybe<TextPosValue>>(!aFrame && !aElm), mRootElm(aRootElm) { // Get the text-position values for the roots and children. // If we find an ARIA text-position value on a DOM element - searching up // from the supplied root DOM element - use the associated frame as the root // frame. This ensures that we're using the proper root frame for comparison.
nsIFrame* ariaFrame = nullptr;
Maybe<TextPosValue> rootAria = GetAriaTextPosValue(aRootElm, ariaFrame); if (rootAria && ariaFrame) {
aRootFrame = ariaFrame;
}
Maybe<TextPosValue> rootLayout = GetLayoutTextPosValue(aRootFrame);
Maybe<TextPosValue> childLayout;
Maybe<TextPosValue> childAria; if (aFrame) {
childLayout = GetLayoutTextPosValue(aFrame);
} if (aElm) {
childAria = GetAriaTextPosValue(aElm);
}
// If there's no child text-position information from ARIA, and the child // layout info is equivalent to the root layout info (i.e., it's inherited), // then we should prefer the root information. if (!childAria && childLayout == rootLayout) {
mIsDefined = false;
}
}
Maybe<TextAttrsMgr::TextPosValue>
TextAttrsMgr::TextPosTextAttr::GetAriaTextPosValue(nsIContent* aElm,
nsIFrame*& ariaFrame) const { // Search for the superscript and subscript roles that imply text-position. const nsIContent* elm = aElm; do { if (elm->IsElement()) { const mozilla::dom::Element* domElm = elm->AsElement(); staticconst dom::Element::AttrValuesArray tokens[] = {
nsGkAtoms::subscript, nsGkAtoms::superscript, nullptr}; const int32_t valueIdx = domElm->FindAttrValueIn(
kNameSpaceID_None, nsGkAtoms::role, tokens, eCaseMatters);
ariaFrame = domElm->GetPrimaryFrame(); if (valueIdx == 0) { return Some(eTextPosSub);
} if (valueIdx == 1) { return Some(eTextPosSuper);
}
}
} while ((elm = elm->GetParent()) && elm != mRootElm);
ariaFrame = nullptr; return Nothing{};
}
Maybe<TextAttrsMgr::TextPosValue>
TextAttrsMgr::TextPosTextAttr::GetLayoutTextPosValue(nsIFrame* aFrame) const { constauto& verticalAlign = aFrame->StyleDisplay()->mVerticalAlign; if (verticalAlign.IsKeyword()) { switch (verticalAlign.AsKeyword()) { case StyleVerticalAlignKeyword::Baseline: return Some(eTextPosBaseline); case StyleVerticalAlignKeyword::Sub: return Some(eTextPosSub); case StyleVerticalAlignKeyword::Super: return Some(eTextPosSuper); // No good guess for the rest, so do not expose value of text-position // attribute. default: return Nothing{};
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.