Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / Source / core / paint / DeprecatedPaintLayerReflectionInfo.cpp
blob629f837897ad5c4c2957334d0c57fe801573ec56
1 /*
2 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All rights reserved.
4 * Portions are Copyright (C) 1998 Netscape Communications Corporation.
6 * Other contributors:
7 * Robert O'Callahan <roc+@cs.cmu.edu>
8 * David Baron <dbaron@fas.harvard.edu>
9 * Christian Biesinger <cbiesinger@web.de>
10 * Randall Jesup <rjesup@wgate.com>
11 * Roland Mainz <roland.mainz@informatik.med.uni-giessen.de>
12 * Josh Soref <timeless@mac.com>
13 * Boris Zbarsky <bzbarsky@mit.edu>
15 * This library is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU Lesser General Public
17 * License as published by the Free Software Foundation; either
18 * version 2.1 of the License, or (at your option) any later version.
20 * This library is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 * Lesser General Public License for more details.
25 * You should have received a copy of the GNU Lesser General Public
26 * License along with this library; if not, write to the Free Software
27 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
29 * Alternatively, the contents of this file may be used under the terms
30 * of either the Mozilla Public License Version 1.1, found at
31 * http://www.mozilla.org/MPL/ (the "MPL") or the GNU General Public
32 * License Version 2.0, found at http://www.fsf.org/copyleft/gpl.html
33 * (the "GPL"), in which case the provisions of the MPL or the GPL are
34 * applicable instead of those above. If you wish to allow use of your
35 * version of this file only under the terms of one of those two
36 * licenses (the MPL or the GPL) and not to allow others to use your
37 * version of this file under the LGPL, indicate your decision by
38 * deletingthe provisions above and replace them with the notice and
39 * other provisions required by the MPL or the GPL, as the case may be.
40 * If you do not delete the provisions above, a recipient may use your
41 * version of this file under any of the LGPL, the MPL or the GPL.
44 #include "config.h"
45 #include "core/paint/DeprecatedPaintLayerReflectionInfo.h"
47 #include "core/frame/UseCounter.h"
48 #include "core/layout/LayoutReplica.h"
49 #include "core/style/ComputedStyle.h"
50 #include "core/paint/DeprecatedPaintLayer.h"
51 #include "core/paint/DeprecatedPaintLayerPainter.h"
52 #include "platform/transforms/ScaleTransformOperation.h"
53 #include "platform/transforms/TranslateTransformOperation.h"
55 #include "wtf/RefPtr.h"
57 namespace blink {
59 DeprecatedPaintLayerReflectionInfo::DeprecatedPaintLayerReflectionInfo(LayoutBox& layoutObject)
60 : m_box(&layoutObject)
61 , m_isPaintingInsideReflection(false)
63 UseCounter::count(box().document(), UseCounter::Reflection);
65 m_reflection = LayoutReplica::createAnonymous(&box().document());
66 m_reflection->setDangerousOneWayParent(m_box);
69 void DeprecatedPaintLayerReflectionInfo::destroy()
71 if (!m_reflection->documentBeingDestroyed())
72 m_reflection->removeLayers(box().layer());
74 m_reflection->setDangerousOneWayParent(nullptr);
75 m_reflection->destroy();
76 m_reflection = nullptr;
79 DeprecatedPaintLayer* DeprecatedPaintLayerReflectionInfo::reflectionLayer() const
81 return m_reflection->layer();
84 void DeprecatedPaintLayerReflectionInfo::updateAfterStyleChange(const ComputedStyle* oldStyle)
86 RefPtr<ComputedStyle> newStyle = ComputedStyle::create();
87 newStyle->inheritFrom(box().styleRef());
89 // Map in our transform.
90 TransformOperations transform;
91 switch (box().style()->boxReflect()->direction()) {
92 case ReflectionBelow:
93 transform.operations().append(TranslateTransformOperation::create(Length(0, Fixed),
94 Length(100., Percent), TransformOperation::Translate));
95 transform.operations().append(TranslateTransformOperation::create(Length(0, Fixed),
96 box().style()->boxReflect()->offset(), TransformOperation::Translate));
97 transform.operations().append(ScaleTransformOperation::create(1.0, -1.0, ScaleTransformOperation::Scale));
98 break;
100 case ReflectionAbove:
101 transform.operations().append(ScaleTransformOperation::create(1.0, -1.0, ScaleTransformOperation::Scale));
102 transform.operations().append(TranslateTransformOperation::create(Length(0, Fixed),
103 Length(100., Percent), TransformOperation::Translate));
104 transform.operations().append(TranslateTransformOperation::create(Length(0, Fixed),
105 box().style()->boxReflect()->offset(), TransformOperation::Translate));
106 break;
108 case ReflectionRight:
109 transform.operations().append(TranslateTransformOperation::create(Length(100., Percent),
110 Length(0, Fixed), TransformOperation::Translate));
111 transform.operations().append(TranslateTransformOperation::create(
112 box().style()->boxReflect()->offset(), Length(0, Fixed), TransformOperation::Translate));
113 transform.operations().append(ScaleTransformOperation::create(-1.0, 1.0, ScaleTransformOperation::Scale));
114 break;
116 case ReflectionLeft:
117 transform.operations().append(ScaleTransformOperation::create(-1.0, 1.0, ScaleTransformOperation::Scale));
118 transform.operations().append(TranslateTransformOperation::create(Length(100., Percent),
119 Length(0, Fixed), TransformOperation::Translate));
120 transform.operations().append(TranslateTransformOperation::create(
121 box().style()->boxReflect()->offset(), Length(0, Fixed), TransformOperation::Translate));
122 break;
124 newStyle->setTransform(transform);
126 // Map in our mask.
127 newStyle->setMaskBoxImage(box().style()->boxReflect()->mask());
129 m_reflection->setStyle(newStyle.release());
132 void DeprecatedPaintLayerReflectionInfo::paint(GraphicsContext* context, const DeprecatedPaintLayerPaintingInfo& paintingInfo, PaintLayerFlags flags)
134 if (m_isPaintingInsideReflection)
135 return;
137 // Mark that we are now inside replica painting.
138 m_isPaintingInsideReflection = true;
139 DeprecatedPaintLayerPainter(*reflectionLayer()).paintLayer(context, paintingInfo, flags);
140 m_isPaintingInsideReflection = false;
143 } // namespace blink