Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* vim: set expandtab shiftwidth=2 tabstop=2: */ |
michael@0 | 3 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 5 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | #include "StyleInfo.h" |
michael@0 | 8 | |
michael@0 | 9 | #include "mozilla/dom/Element.h" |
michael@0 | 10 | #include "nsComputedDOMStyle.h" |
michael@0 | 11 | #include "nsCSSProps.h" |
michael@0 | 12 | #include "nsIFrame.h" |
michael@0 | 13 | |
michael@0 | 14 | using namespace mozilla; |
michael@0 | 15 | using namespace mozilla::a11y; |
michael@0 | 16 | |
michael@0 | 17 | StyleInfo::StyleInfo(dom::Element* aElement, nsIPresShell* aPresShell) : |
michael@0 | 18 | mElement(aElement) |
michael@0 | 19 | { |
michael@0 | 20 | mStyleContext = |
michael@0 | 21 | nsComputedDOMStyle::GetStyleContextForElementNoFlush(aElement, |
michael@0 | 22 | nullptr, |
michael@0 | 23 | aPresShell); |
michael@0 | 24 | } |
michael@0 | 25 | |
michael@0 | 26 | void |
michael@0 | 27 | StyleInfo::Display(nsAString& aValue) |
michael@0 | 28 | { |
michael@0 | 29 | aValue.Truncate(); |
michael@0 | 30 | AppendASCIItoUTF16( |
michael@0 | 31 | nsCSSProps::ValueToKeyword(mStyleContext->StyleDisplay()->mDisplay, |
michael@0 | 32 | nsCSSProps::kDisplayKTable), aValue); |
michael@0 | 33 | } |
michael@0 | 34 | |
michael@0 | 35 | void |
michael@0 | 36 | StyleInfo::TextAlign(nsAString& aValue) |
michael@0 | 37 | { |
michael@0 | 38 | aValue.Truncate(); |
michael@0 | 39 | AppendASCIItoUTF16( |
michael@0 | 40 | nsCSSProps::ValueToKeyword(mStyleContext->StyleText()->mTextAlign, |
michael@0 | 41 | nsCSSProps::kTextAlignKTable), aValue); |
michael@0 | 42 | } |
michael@0 | 43 | |
michael@0 | 44 | void |
michael@0 | 45 | StyleInfo::TextIndent(nsAString& aValue) |
michael@0 | 46 | { |
michael@0 | 47 | aValue.Truncate(); |
michael@0 | 48 | |
michael@0 | 49 | const nsStyleCoord& styleCoord = |
michael@0 | 50 | mStyleContext->StyleText()->mTextIndent; |
michael@0 | 51 | |
michael@0 | 52 | nscoord coordVal = 0; |
michael@0 | 53 | switch (styleCoord.GetUnit()) { |
michael@0 | 54 | case eStyleUnit_Coord: |
michael@0 | 55 | coordVal = styleCoord.GetCoordValue(); |
michael@0 | 56 | break; |
michael@0 | 57 | |
michael@0 | 58 | case eStyleUnit_Percent: |
michael@0 | 59 | { |
michael@0 | 60 | nsIFrame* frame = mElement->GetPrimaryFrame(); |
michael@0 | 61 | nsIFrame* containerFrame = frame->GetContainingBlock(); |
michael@0 | 62 | nscoord percentageBase = containerFrame->GetContentRect().width; |
michael@0 | 63 | coordVal = NSCoordSaturatingMultiply(percentageBase, |
michael@0 | 64 | styleCoord.GetPercentValue()); |
michael@0 | 65 | break; |
michael@0 | 66 | } |
michael@0 | 67 | |
michael@0 | 68 | case eStyleUnit_Null: |
michael@0 | 69 | case eStyleUnit_Normal: |
michael@0 | 70 | case eStyleUnit_Auto: |
michael@0 | 71 | case eStyleUnit_None: |
michael@0 | 72 | case eStyleUnit_Factor: |
michael@0 | 73 | case eStyleUnit_Degree: |
michael@0 | 74 | case eStyleUnit_Grad: |
michael@0 | 75 | case eStyleUnit_Radian: |
michael@0 | 76 | case eStyleUnit_Turn: |
michael@0 | 77 | case eStyleUnit_FlexFraction: |
michael@0 | 78 | case eStyleUnit_Integer: |
michael@0 | 79 | case eStyleUnit_Enumerated: |
michael@0 | 80 | case eStyleUnit_Calc: |
michael@0 | 81 | break; |
michael@0 | 82 | } |
michael@0 | 83 | |
michael@0 | 84 | aValue.AppendFloat(nsPresContext::AppUnitsToFloatCSSPixels(coordVal)); |
michael@0 | 85 | aValue.AppendLiteral("px"); |
michael@0 | 86 | } |
michael@0 | 87 | |
michael@0 | 88 | void |
michael@0 | 89 | StyleInfo::Margin(css::Side aSide, nsAString& aValue) |
michael@0 | 90 | { |
michael@0 | 91 | aValue.Truncate(); |
michael@0 | 92 | |
michael@0 | 93 | nscoord coordVal = mElement->GetPrimaryFrame()->GetUsedMargin().Side(aSide); |
michael@0 | 94 | aValue.AppendFloat(nsPresContext::AppUnitsToFloatCSSPixels(coordVal)); |
michael@0 | 95 | aValue.AppendLiteral("px"); |
michael@0 | 96 | } |
michael@0 | 97 | |
michael@0 | 98 | void |
michael@0 | 99 | StyleInfo::FormatColor(const nscolor& aValue, nsString& aFormattedValue) |
michael@0 | 100 | { |
michael@0 | 101 | // Combine the string like rgb(R, G, B) from nscolor. |
michael@0 | 102 | aFormattedValue.AppendLiteral("rgb("); |
michael@0 | 103 | aFormattedValue.AppendInt(NS_GET_R(aValue)); |
michael@0 | 104 | aFormattedValue.AppendLiteral(", "); |
michael@0 | 105 | aFormattedValue.AppendInt(NS_GET_G(aValue)); |
michael@0 | 106 | aFormattedValue.AppendLiteral(", "); |
michael@0 | 107 | aFormattedValue.AppendInt(NS_GET_B(aValue)); |
michael@0 | 108 | aFormattedValue.Append(')'); |
michael@0 | 109 | } |
michael@0 | 110 | |
michael@0 | 111 | void |
michael@0 | 112 | StyleInfo::FormatFontStyle(const nscoord& aValue, nsAString& aFormattedValue) |
michael@0 | 113 | { |
michael@0 | 114 | nsCSSKeyword keyword = |
michael@0 | 115 | nsCSSProps::ValueToKeywordEnum(aValue, nsCSSProps::kFontStyleKTable); |
michael@0 | 116 | AppendUTF8toUTF16(nsCSSKeywords::GetStringValue(keyword), aFormattedValue); |
michael@0 | 117 | } |
michael@0 | 118 | |
michael@0 | 119 | void |
michael@0 | 120 | StyleInfo::FormatTextDecorationStyle(uint8_t aValue, nsAString& aFormattedValue) |
michael@0 | 121 | { |
michael@0 | 122 | nsCSSKeyword keyword = |
michael@0 | 123 | nsCSSProps::ValueToKeywordEnum(aValue, |
michael@0 | 124 | nsCSSProps::kTextDecorationStyleKTable); |
michael@0 | 125 | AppendUTF8toUTF16(nsCSSKeywords::GetStringValue(keyword), aFormattedValue); |
michael@0 | 126 | } |