summaryrefslogtreecommitdiff
path: root/xfa/fde/css/cfde_csscomputedstyle.cpp
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2017-01-19 10:27:58 -0500
committerChromium commit bot <commit-bot@chromium.org>2017-01-19 15:49:07 +0000
commit95bec8046a28928df627ce4d48eee8b209b3e36e (patch)
tree46913cf24aacfc88a89bb55edcce8e3a2e724c4b /xfa/fde/css/cfde_csscomputedstyle.cpp
parentdd533baad22f5143c093b98e98463a0dc62899ea (diff)
downloadpdfium-95bec8046a28928df627ce4d48eee8b209b3e36e.tar.xz
Split fde/css files into individual class files.
This CL splits the files in xfa/fde/css into class per file and renames any needed files to match the class names. Update some of the classes to use std::stack. Change-Id: I4eca0fb3556d949a15a873bb0f0fd732f47e4fb1 Reviewed-on: https://pdfium-review.googlesource.com/2253 Commit-Queue: dsinclair <dsinclair@chromium.org> Reviewed-by: Tom Sepez <tsepez@chromium.org> Reviewed-by: Nicolás Peña <npm@chromium.org>
Diffstat (limited to 'xfa/fde/css/cfde_csscomputedstyle.cpp')
-rw-r--r--xfa/fde/css/cfde_csscomputedstyle.cpp204
1 files changed, 204 insertions, 0 deletions
diff --git a/xfa/fde/css/cfde_csscomputedstyle.cpp b/xfa/fde/css/cfde_csscomputedstyle.cpp
new file mode 100644
index 0000000000..010f573c04
--- /dev/null
+++ b/xfa/fde/css/cfde_csscomputedstyle.cpp
@@ -0,0 +1,204 @@
+// Copyright 2017 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "xfa/fde/css/cfde_csscomputedstyle.h"
+
+#include "third_party/base/stl_util.h"
+#include "xfa/fde/css/cfde_cssstringvalue.h"
+#include "xfa/fde/css/cfde_cssvaluelist.h"
+
+CFDE_CSSComputedStyle::CFDE_CSSComputedStyle() : m_dwRefCount(1) {}
+
+CFDE_CSSComputedStyle::~CFDE_CSSComputedStyle() {}
+
+uint32_t CFDE_CSSComputedStyle::Retain() {
+ return ++m_dwRefCount;
+}
+
+uint32_t CFDE_CSSComputedStyle::Release() {
+ uint32_t dwRefCount = --m_dwRefCount;
+ if (dwRefCount == 0)
+ delete this;
+ return dwRefCount;
+}
+
+bool CFDE_CSSComputedStyle::GetCustomStyle(const CFX_WideStringC& wsName,
+ CFX_WideString& wsValue) const {
+ for (int32_t i = pdfium::CollectionSize<int32_t>(m_CustomProperties) - 2;
+ i > -1; i -= 2) {
+ if (wsName == m_CustomProperties[i]) {
+ wsValue = m_CustomProperties[i + 1];
+ return true;
+ }
+ }
+ return false;
+}
+
+int32_t CFDE_CSSComputedStyle::CountFontFamilies() const {
+ return m_InheritedData.m_pFontFamily
+ ? m_InheritedData.m_pFontFamily->CountValues()
+ : 0;
+}
+
+const CFX_WideString CFDE_CSSComputedStyle::GetFontFamily(int32_t index) const {
+ return static_cast<CFDE_CSSStringValue*>(
+ m_InheritedData.m_pFontFamily->GetValue(index))
+ ->Value();
+}
+
+uint16_t CFDE_CSSComputedStyle::GetFontWeight() const {
+ return m_InheritedData.m_wFontWeight;
+}
+
+FDE_CSSFontVariant CFDE_CSSComputedStyle::GetFontVariant() const {
+ return m_InheritedData.m_eFontVariant;
+}
+
+FDE_CSSFontStyle CFDE_CSSComputedStyle::GetFontStyle() const {
+ return m_InheritedData.m_eFontStyle;
+}
+
+FX_FLOAT CFDE_CSSComputedStyle::GetFontSize() const {
+ return m_InheritedData.m_fFontSize;
+}
+
+FX_ARGB CFDE_CSSComputedStyle::GetColor() const {
+ return m_InheritedData.m_dwFontColor;
+}
+
+void CFDE_CSSComputedStyle::SetFontWeight(uint16_t wFontWeight) {
+ m_InheritedData.m_wFontWeight = wFontWeight;
+}
+
+void CFDE_CSSComputedStyle::SetFontVariant(FDE_CSSFontVariant eFontVariant) {
+ m_InheritedData.m_eFontVariant = eFontVariant;
+}
+
+void CFDE_CSSComputedStyle::SetFontStyle(FDE_CSSFontStyle eFontStyle) {
+ m_InheritedData.m_eFontStyle = eFontStyle;
+}
+
+void CFDE_CSSComputedStyle::SetFontSize(FX_FLOAT fFontSize) {
+ m_InheritedData.m_fFontSize = fFontSize;
+}
+
+void CFDE_CSSComputedStyle::SetColor(FX_ARGB dwFontColor) {
+ m_InheritedData.m_dwFontColor = dwFontColor;
+}
+
+const FDE_CSSRect* CFDE_CSSComputedStyle::GetBorderWidth() const {
+ return m_NonInheritedData.m_bHasBorder ? &(m_NonInheritedData.m_BorderWidth)
+ : nullptr;
+}
+
+const FDE_CSSRect* CFDE_CSSComputedStyle::GetMarginWidth() const {
+ return m_NonInheritedData.m_bHasMargin ? &(m_NonInheritedData.m_MarginWidth)
+ : nullptr;
+}
+
+const FDE_CSSRect* CFDE_CSSComputedStyle::GetPaddingWidth() const {
+ return m_NonInheritedData.m_bHasPadding ? &(m_NonInheritedData.m_PaddingWidth)
+ : nullptr;
+}
+
+void CFDE_CSSComputedStyle::SetMarginWidth(const FDE_CSSRect& rect) {
+ m_NonInheritedData.m_MarginWidth = rect;
+ m_NonInheritedData.m_bHasMargin = true;
+}
+
+void CFDE_CSSComputedStyle::SetPaddingWidth(const FDE_CSSRect& rect) {
+ m_NonInheritedData.m_PaddingWidth = rect;
+ m_NonInheritedData.m_bHasPadding = true;
+}
+
+FDE_CSSDisplay CFDE_CSSComputedStyle::GetDisplay() const {
+ return m_NonInheritedData.m_eDisplay;
+}
+
+FX_FLOAT CFDE_CSSComputedStyle::GetLineHeight() const {
+ return m_InheritedData.m_fLineHeight;
+}
+
+const FDE_CSSLength& CFDE_CSSComputedStyle::GetTextIndent() const {
+ return m_InheritedData.m_TextIndent;
+}
+
+FDE_CSSTextAlign CFDE_CSSComputedStyle::GetTextAlign() const {
+ return m_InheritedData.m_eTextAlign;
+}
+
+FDE_CSSVerticalAlign CFDE_CSSComputedStyle::GetVerticalAlign() const {
+ return m_NonInheritedData.m_eVerticalAlign;
+}
+
+FX_FLOAT CFDE_CSSComputedStyle::GetNumberVerticalAlign() const {
+ return m_NonInheritedData.m_fVerticalAlign;
+}
+
+uint32_t CFDE_CSSComputedStyle::GetTextDecoration() const {
+ return m_NonInheritedData.m_dwTextDecoration;
+}
+
+const FDE_CSSLength& CFDE_CSSComputedStyle::GetLetterSpacing() const {
+ return m_InheritedData.m_LetterSpacing;
+}
+
+void CFDE_CSSComputedStyle::SetLineHeight(FX_FLOAT fLineHeight) {
+ m_InheritedData.m_fLineHeight = fLineHeight;
+}
+
+void CFDE_CSSComputedStyle::SetTextIndent(const FDE_CSSLength& textIndent) {
+ m_InheritedData.m_TextIndent = textIndent;
+}
+
+void CFDE_CSSComputedStyle::SetTextAlign(FDE_CSSTextAlign eTextAlign) {
+ m_InheritedData.m_eTextAlign = eTextAlign;
+}
+
+void CFDE_CSSComputedStyle::SetNumberVerticalAlign(FX_FLOAT fAlign) {
+ m_NonInheritedData.m_eVerticalAlign = FDE_CSSVerticalAlign::Number,
+ m_NonInheritedData.m_fVerticalAlign = fAlign;
+}
+
+void CFDE_CSSComputedStyle::SetTextDecoration(uint32_t dwTextDecoration) {
+ m_NonInheritedData.m_dwTextDecoration = dwTextDecoration;
+}
+
+void CFDE_CSSComputedStyle::SetLetterSpacing(
+ const FDE_CSSLength& letterSpacing) {
+ m_InheritedData.m_LetterSpacing = letterSpacing;
+}
+
+void CFDE_CSSComputedStyle::AddCustomStyle(const CFX_WideString& wsName,
+ const CFX_WideString& wsValue) {
+ m_CustomProperties.push_back(wsName);
+ m_CustomProperties.push_back(wsValue);
+}
+
+CFDE_CSSComputedStyle::InheritedData::InheritedData()
+ : m_LetterSpacing(FDE_CSSLengthUnit::Normal),
+ m_WordSpacing(FDE_CSSLengthUnit::Normal),
+ m_TextIndent(FDE_CSSLengthUnit::Point, 0),
+ m_pFontFamily(nullptr),
+ m_fFontSize(12.0f),
+ m_fLineHeight(14.0f),
+ m_dwFontColor(0xFF000000),
+ m_wFontWeight(400),
+ m_eFontVariant(FDE_CSSFontVariant::Normal),
+ m_eFontStyle(FDE_CSSFontStyle::Normal),
+ m_eTextAlign(FDE_CSSTextAlign::Left) {}
+
+CFDE_CSSComputedStyle::NonInheritedData::NonInheritedData()
+ : m_MarginWidth(FDE_CSSLengthUnit::Point, 0),
+ m_BorderWidth(FDE_CSSLengthUnit::Point, 0),
+ m_PaddingWidth(FDE_CSSLengthUnit::Point, 0),
+ m_fVerticalAlign(0.0f),
+ m_eDisplay(FDE_CSSDisplay::Inline),
+ m_eVerticalAlign(FDE_CSSVerticalAlign::Baseline),
+ m_dwTextDecoration(0),
+ m_bHasMargin(false),
+ m_bHasBorder(false),
+ m_bHasPadding(false) {}