1 /* 2 * Copyright (C) 1999 Antti Koivisto (koivisto (at) kde.org) 3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. 4 * 5 * This library is free software; you can redistribute it and/or 6 * modify it under the terms of the GNU Library General Public 7 * License as published by the Free Software Foundation; either 8 * version 2 of the License, or (at your option) any later version. 9 * 10 * This library is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 * Library General Public License for more details. 14 * 15 * You should have received a copy of the GNU Library General Public License 16 * along with this library; see the file COPYING.LIB. If not, write to 17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 18 * Boston, MA 02110-1301, USA. 19 * 20 */ 21 22 #include "config.h" 23 #include "core/rendering/style/ShadowData.h" 24 25 #include "core/platform/graphics/LayoutRect.h" 26 27 using namespace std; 28 29 namespace WebCore { 30 31 ShadowData::ShadowData(const ShadowData& o) 32 : m_location(o.m_location) 33 , m_blur(o.m_blur) 34 , m_spread(o.m_spread) 35 , m_color(o.m_color) 36 , m_style(o.m_style) 37 , m_next(o.m_next ? adoptPtr(new ShadowData(*o.m_next)) : nullptr) 38 { 39 } 40 41 bool ShadowData::operator==(const ShadowData& o) const 42 { 43 if ((m_next && !o.m_next) || (!m_next && o.m_next) 44 || (m_next && o.m_next && *m_next != *o.m_next)) 45 return false; 46 47 return m_location == o.m_location 48 && m_blur == o.m_blur 49 && m_spread == o.m_spread 50 && m_style == o.m_style 51 && m_color == o.m_color; 52 } 53 54 static inline void calculateShadowExtent(const ShadowData* shadow, int additionalOutlineSize, int& shadowLeft, int& shadowRight, int& shadowTop, int& shadowBottom) 55 { 56 do { 57 int blurAndSpread = shadow->blur() + shadow->spread() + additionalOutlineSize; 58 if (shadow->style() == Normal) { 59 shadowLeft = min(shadow->x() - blurAndSpread, shadowLeft); 60 shadowRight = max(shadow->x() + blurAndSpread, shadowRight); 61 shadowTop = min(shadow->y() - blurAndSpread, shadowTop); 62 shadowBottom = max(shadow->y() + blurAndSpread, shadowBottom); 63 } 64 65 shadow = shadow->next(); 66 } while (shadow); 67 } 68 69 void ShadowData::adjustRectForShadow(LayoutRect& rect, int additionalOutlineSize) const 70 { 71 int shadowLeft = 0; 72 int shadowRight = 0; 73 int shadowTop = 0; 74 int shadowBottom = 0; 75 calculateShadowExtent(this, additionalOutlineSize, shadowLeft, shadowRight, shadowTop, shadowBottom); 76 77 rect.move(shadowLeft, shadowTop); 78 rect.setWidth(rect.width() - shadowLeft + shadowRight); 79 rect.setHeight(rect.height() - shadowTop + shadowBottom); 80 } 81 82 void ShadowData::adjustRectForShadow(FloatRect& rect, int additionalOutlineSize) const 83 { 84 int shadowLeft = 0; 85 int shadowRight = 0; 86 int shadowTop = 0; 87 int shadowBottom = 0; 88 calculateShadowExtent(this, additionalOutlineSize, shadowLeft, shadowRight, shadowTop, shadowBottom); 89 90 rect.move(shadowLeft, shadowTop); 91 rect.setWidth(rect.width() - shadowLeft + shadowRight); 92 rect.setHeight(rect.height() - shadowTop + shadowBottom); 93 } 94 95 } // namespace WebCore 96