author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Mon, 03 May 2010 13:17:34 +0300 | |
changeset 19 | fcece45ef507 |
parent 0 | 1918ee327afb |
child 30 | 5dc02b23752f |
permissions | -rw-r--r-- |
0 | 1 |
/* |
2 |
* Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
|
3 |
* (C) 1999 Antti Koivisto (koivisto@kde.org) |
|
4 |
* (C) 2005 Allan Sandfeld Jensen (kde@carewolf.com) |
|
5 |
* (C) 2005, 2006 Samuel Weinig (sam.weinig@gmail.com) |
|
6 |
* Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. |
|
7 |
* |
|
8 |
* This library is free software; you can redistribute it and/or |
|
9 |
* modify it under the terms of the GNU Library General Public |
|
10 |
* License as published by the Free Software Foundation; either |
|
11 |
* version 2 of the License, or (at your option) any later version. |
|
12 |
* |
|
13 |
* This library is distributed in the hope that it will be useful, |
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
16 |
* Library General Public License for more details. |
|
17 |
* |
|
18 |
* You should have received a copy of the GNU Library General Public License |
|
19 |
* along with this library; see the file COPYING.LIB. If not, write to |
|
20 |
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
|
21 |
* Boston, MA 02110-1301, USA. |
|
22 |
* |
|
23 |
*/ |
|
24 |
||
25 |
#include "config.h" |
|
26 |
#include "RenderBoxModelObject.h" |
|
27 |
||
28 |
#include "GraphicsContext.h" |
|
29 |
#include "HTMLElement.h" |
|
30 |
#include "HTMLNames.h" |
|
31 |
#include "ImageBuffer.h" |
|
32 |
#include "RenderBlock.h" |
|
33 |
#include "RenderInline.h" |
|
34 |
#include "RenderLayer.h" |
|
35 |
#include "RenderView.h" |
|
36 |
||
37 |
using namespace std; |
|
38 |
||
39 |
namespace WebCore { |
|
40 |
||
41 |
using namespace HTMLNames; |
|
42 |
||
43 |
bool RenderBoxModelObject::s_wasFloating = false; |
|
44 |
bool RenderBoxModelObject::s_hadLayer = false; |
|
45 |
bool RenderBoxModelObject::s_layerWasSelfPainting = false; |
|
46 |
||
47 |
RenderBoxModelObject::RenderBoxModelObject(Node* node) |
|
48 |
: RenderObject(node) |
|
49 |
, m_layer(0) |
|
50 |
{ |
|
51 |
} |
|
52 |
||
53 |
RenderBoxModelObject::~RenderBoxModelObject() |
|
54 |
{ |
|
55 |
// Our layer should have been destroyed and cleared by now |
|
56 |
ASSERT(!hasLayer()); |
|
57 |
ASSERT(!m_layer); |
|
58 |
} |
|
59 |
||
60 |
void RenderBoxModelObject::destroyLayer() |
|
61 |
{ |
|
62 |
ASSERT(!hasLayer()); // Callers should have already called setHasLayer(false) |
|
63 |
ASSERT(m_layer); |
|
64 |
m_layer->destroy(renderArena()); |
|
65 |
m_layer = 0; |
|
66 |
} |
|
67 |
||
68 |
void RenderBoxModelObject::destroy() |
|
69 |
{ |
|
70 |
// This must be done before we destroy the RenderObject. |
|
71 |
if (m_layer) |
|
72 |
m_layer->clearClipRects(); |
|
73 |
||
74 |
// RenderObject::destroy calls back to destroyLayer() for layer destruction |
|
75 |
RenderObject::destroy(); |
|
76 |
} |
|
77 |
||
78 |
bool RenderBoxModelObject::hasSelfPaintingLayer() const |
|
79 |
{ |
|
80 |
return m_layer && m_layer->isSelfPaintingLayer(); |
|
81 |
} |
|
82 |
||
83 |
void RenderBoxModelObject::styleWillChange(StyleDifference diff, const RenderStyle* newStyle) |
|
84 |
{ |
|
85 |
s_wasFloating = isFloating(); |
|
86 |
s_hadLayer = hasLayer(); |
|
87 |
if (s_hadLayer) |
|
88 |
s_layerWasSelfPainting = layer()->isSelfPaintingLayer(); |
|
89 |
||
90 |
// If our z-index changes value or our visibility changes, |
|
91 |
// we need to dirty our stacking context's z-order list. |
|
92 |
if (style() && newStyle) { |
|
93 |
if (parent()) { |
|
94 |
// Do a repaint with the old style first, e.g., for example if we go from |
|
95 |
// having an outline to not having an outline. |
|
96 |
if (diff == StyleDifferenceRepaintLayer) { |
|
97 |
layer()->repaintIncludingDescendants(); |
|
98 |
if (!(style()->clip() == newStyle->clip())) |
|
99 |
layer()->clearClipRectsIncludingDescendants(); |
|
100 |
} else if (diff == StyleDifferenceRepaint || newStyle->outlineSize() < style()->outlineSize()) |
|
101 |
repaint(); |
|
102 |
} |
|
103 |
||
104 |
if (diff == StyleDifferenceLayout) { |
|
105 |
// When a layout hint happens, we go ahead and do a repaint of the layer, since the layer could |
|
106 |
// end up being destroyed. |
|
107 |
if (hasLayer()) { |
|
108 |
if (style()->position() != newStyle->position() || |
|
109 |
style()->zIndex() != newStyle->zIndex() || |
|
110 |
style()->hasAutoZIndex() != newStyle->hasAutoZIndex() || |
|
111 |
!(style()->clip() == newStyle->clip()) || |
|
112 |
style()->hasClip() != newStyle->hasClip() || |
|
113 |
style()->opacity() != newStyle->opacity() || |
|
114 |
style()->transform() != newStyle->transform()) |
|
115 |
layer()->repaintIncludingDescendants(); |
|
116 |
} else if (newStyle->hasTransform() || newStyle->opacity() < 1) { |
|
117 |
// If we don't have a layer yet, but we are going to get one because of transform or opacity, |
|
118 |
// then we need to repaint the old position of the object. |
|
119 |
repaint(); |
|
120 |
} |
|
121 |
} |
|
122 |
||
123 |
if (hasLayer() && (style()->hasAutoZIndex() != newStyle->hasAutoZIndex() || |
|
124 |
style()->zIndex() != newStyle->zIndex() || |
|
125 |
style()->visibility() != newStyle->visibility())) { |
|
126 |
layer()->dirtyStackingContextZOrderLists(); |
|
127 |
if (style()->hasAutoZIndex() != newStyle->hasAutoZIndex() || style()->visibility() != newStyle->visibility()) |
|
128 |
layer()->dirtyZOrderLists(); |
|
129 |
} |
|
130 |
} |
|
131 |
||
132 |
RenderObject::styleWillChange(diff, newStyle); |
|
133 |
} |
|
134 |
||
135 |
void RenderBoxModelObject::styleDidChange(StyleDifference diff, const RenderStyle* oldStyle) |
|
136 |
{ |
|
137 |
RenderObject::styleDidChange(diff, oldStyle); |
|
138 |
updateBoxModelInfoFromStyle(); |
|
139 |
||
140 |
if (requiresLayer()) { |
|
141 |
if (!layer()) { |
|
142 |
if (s_wasFloating && isFloating()) |
|
143 |
setChildNeedsLayout(true); |
|
144 |
m_layer = new (renderArena()) RenderLayer(this); |
|
145 |
setHasLayer(true); |
|
146 |
m_layer->insertOnlyThisLayer(); |
|
147 |
if (parent() && !needsLayout() && containingBlock()) |
|
148 |
m_layer->updateLayerPositions(); |
|
149 |
} |
|
150 |
} else if (layer() && layer()->parent()) { |
|
151 |
setHasTransform(false); // Either a transform wasn't specified or the object doesn't support transforms, so just null out the bit. |
|
152 |
setHasReflection(false); |
|
153 |
m_layer->removeOnlyThisLayer(); // calls destroyLayer() which clears m_layer |
|
154 |
if (s_wasFloating && isFloating()) |
|
155 |
setChildNeedsLayout(true); |
|
156 |
} |
|
157 |
||
158 |
if (layer()) { |
|
159 |
layer()->styleChanged(diff, oldStyle); |
|
160 |
if (s_hadLayer && layer()->isSelfPaintingLayer() != s_layerWasSelfPainting) |
|
161 |
setChildNeedsLayout(true); |
|
162 |
} |
|
163 |
} |
|
164 |
||
165 |
void RenderBoxModelObject::updateBoxModelInfoFromStyle() |
|
166 |
{ |
|
167 |
// Set the appropriate bits for a box model object. Since all bits are cleared in styleWillChange, |
|
168 |
// we only check for bits that could possibly be set to true. |
|
169 |
setHasBoxDecorations(style()->hasBorder() || style()->hasBackground() || style()->hasAppearance() || style()->boxShadow()); |
|
170 |
setInline(style()->isDisplayInlineType()); |
|
171 |
setRelPositioned(style()->position() == RelativePosition); |
|
172 |
} |
|
173 |
||
174 |
int RenderBoxModelObject::relativePositionOffsetX() const |
|
175 |
{ |
|
176 |
// Objects that shrink to avoid floats normally use available line width when computing containing block width. However |
|
177 |
// in the case of relative positioning using percentages, we can't do this. The offset should always be resolved using the |
|
178 |
// available width of the containing block. Therefore we don't use containingBlockWidthForContent() here, but instead explicitly |
|
179 |
// call availableWidth on our containing block. |
|
180 |
if (!style()->left().isAuto()) { |
|
181 |
RenderBlock* cb = containingBlock(); |
|
182 |
if (!style()->right().isAuto() && containingBlock()->style()->direction() == RTL) |
|
183 |
return -style()->right().calcValue(cb->availableWidth()); |
|
184 |
return style()->left().calcValue(cb->availableWidth()); |
|
185 |
} |
|
186 |
if (!style()->right().isAuto()) { |
|
187 |
RenderBlock* cb = containingBlock(); |
|
188 |
return -style()->right().calcValue(cb->availableWidth()); |
|
189 |
} |
|
190 |
return 0; |
|
191 |
} |
|
192 |
||
193 |
int RenderBoxModelObject::relativePositionOffsetY() const |
|
194 |
{ |
|
195 |
if (!style()->top().isAuto()) |
|
196 |
return style()->top().calcValue(containingBlock()->availableHeight()); |
|
197 |
else if (!style()->bottom().isAuto()) |
|
198 |
return -style()->bottom().calcValue(containingBlock()->availableHeight()); |
|
199 |
||
200 |
return 0; |
|
201 |
} |
|
202 |
||
203 |
int RenderBoxModelObject::offsetLeft() const |
|
204 |
{ |
|
205 |
// If the element is the HTML body element or does not have an associated box |
|
206 |
// return 0 and stop this algorithm. |
|
207 |
if (isBody()) |
|
208 |
return 0; |
|
209 |
||
210 |
RenderBoxModelObject* offsetPar = offsetParent(); |
|
211 |
int xPos = (isBox() ? toRenderBox(this)->x() : 0); |
|
212 |
||
213 |
// If the offsetParent of the element is null, or is the HTML body element, |
|
214 |
// return the distance between the canvas origin and the left border edge |
|
215 |
// of the element and stop this algorithm. |
|
216 |
if (offsetPar) { |
|
217 |
if (offsetPar->isBox() && !offsetPar->isBody()) |
|
218 |
xPos -= toRenderBox(offsetPar)->borderLeft(); |
|
219 |
if (!isPositioned()) { |
|
220 |
if (isRelPositioned()) |
|
221 |
xPos += relativePositionOffsetX(); |
|
222 |
RenderObject* curr = parent(); |
|
223 |
while (curr && curr != offsetPar) { |
|
224 |
// FIXME: What are we supposed to do inside SVG content? |
|
225 |
if (curr->isBox() && !curr->isTableRow()) |
|
226 |
xPos += toRenderBox(curr)->x(); |
|
227 |
curr = curr->parent(); |
|
228 |
} |
|
229 |
if (offsetPar->isBox() && offsetPar->isBody() && !offsetPar->isRelPositioned() && !offsetPar->isPositioned()) |
|
230 |
xPos += toRenderBox(offsetPar)->x(); |
|
231 |
} |
|
232 |
} |
|
233 |
||
234 |
return xPos; |
|
235 |
} |
|
236 |
||
237 |
int RenderBoxModelObject::offsetTop() const |
|
238 |
{ |
|
239 |
// If the element is the HTML body element or does not have an associated box |
|
240 |
// return 0 and stop this algorithm. |
|
241 |
if (isBody()) |
|
242 |
return 0; |
|
243 |
||
244 |
RenderBoxModelObject* offsetPar = offsetParent(); |
|
245 |
int yPos = (isBox() ? toRenderBox(this)->y() : 0); |
|
246 |
||
247 |
// If the offsetParent of the element is null, or is the HTML body element, |
|
248 |
// return the distance between the canvas origin and the top border edge |
|
249 |
// of the element and stop this algorithm. |
|
250 |
if (offsetPar) { |
|
251 |
if (offsetPar->isBox() && !offsetPar->isBody()) |
|
252 |
yPos -= toRenderBox(offsetPar)->borderTop(); |
|
253 |
if (!isPositioned()) { |
|
254 |
if (isRelPositioned()) |
|
255 |
yPos += relativePositionOffsetY(); |
|
256 |
RenderObject* curr = parent(); |
|
257 |
while (curr && curr != offsetPar) { |
|
258 |
// FIXME: What are we supposed to do inside SVG content? |
|
259 |
if (curr->isBox() && !curr->isTableRow()) |
|
260 |
yPos += toRenderBox(curr)->y(); |
|
261 |
curr = curr->parent(); |
|
262 |
} |
|
263 |
if (offsetPar->isBox() && offsetPar->isBody() && !offsetPar->isRelPositioned() && !offsetPar->isPositioned()) |
|
264 |
yPos += toRenderBox(offsetPar)->y(); |
|
265 |
} |
|
266 |
} |
|
267 |
return yPos; |
|
268 |
} |
|
269 |
||
270 |
int RenderBoxModelObject::paddingTop(bool) const |
|
271 |
{ |
|
272 |
int w = 0; |
|
273 |
Length padding = style()->paddingTop(); |
|
274 |
if (padding.isPercent()) |
|
275 |
w = containingBlock()->availableWidth(); |
|
276 |
return padding.calcMinValue(w); |
|
277 |
} |
|
278 |
||
279 |
int RenderBoxModelObject::paddingBottom(bool) const |
|
280 |
{ |
|
281 |
int w = 0; |
|
282 |
Length padding = style()->paddingBottom(); |
|
283 |
if (padding.isPercent()) |
|
284 |
w = containingBlock()->availableWidth(); |
|
285 |
return padding.calcMinValue(w); |
|
286 |
} |
|
287 |
||
288 |
int RenderBoxModelObject::paddingLeft(bool) const |
|
289 |
{ |
|
290 |
int w = 0; |
|
291 |
Length padding = style()->paddingLeft(); |
|
292 |
if (padding.isPercent()) |
|
293 |
w = containingBlock()->availableWidth(); |
|
294 |
return padding.calcMinValue(w); |
|
295 |
} |
|
296 |
||
297 |
int RenderBoxModelObject::paddingRight(bool) const |
|
298 |
{ |
|
299 |
int w = 0; |
|
300 |
Length padding = style()->paddingRight(); |
|
301 |
if (padding.isPercent()) |
|
302 |
w = containingBlock()->availableWidth(); |
|
303 |
return padding.calcMinValue(w); |
|
304 |
} |
|
305 |
||
306 |
||
307 |
void RenderBoxModelObject::paintFillLayerExtended(const PaintInfo& paintInfo, const Color& c, const FillLayer* bgLayer, int tx, int ty, int w, int h, InlineFlowBox* box, CompositeOperator op) |
|
308 |
{ |
|
309 |
GraphicsContext* context = paintInfo.context; |
|
310 |
bool includeLeftEdge = box ? box->includeLeftEdge() : true; |
|
311 |
bool includeRightEdge = box ? box->includeRightEdge() : true; |
|
312 |
int bLeft = includeLeftEdge ? borderLeft() : 0; |
|
313 |
int bRight = includeRightEdge ? borderRight() : 0; |
|
314 |
int pLeft = includeLeftEdge ? paddingLeft() : 0; |
|
315 |
int pRight = includeRightEdge ? paddingRight() : 0; |
|
316 |
||
317 |
bool clippedToBorderRadius = false; |
|
318 |
if (style()->hasBorderRadius() && (includeLeftEdge || includeRightEdge)) { |
|
319 |
IntRect borderRect(tx, ty, w, h); |
|
320 |
||
321 |
if (borderRect.isEmpty()) |
|
322 |
return; |
|
323 |
||
324 |
context->save(); |
|
325 |
||
326 |
IntSize topLeft, topRight, bottomLeft, bottomRight; |
|
327 |
style()->getBorderRadiiForRect(borderRect, topLeft, topRight, bottomLeft, bottomRight); |
|
328 |
||
329 |
context->addRoundedRectClip(borderRect, includeLeftEdge ? topLeft : IntSize(), |
|
330 |
includeRightEdge ? topRight : IntSize(), |
|
331 |
includeLeftEdge ? bottomLeft : IntSize(), |
|
332 |
includeRightEdge ? bottomRight : IntSize()); |
|
333 |
clippedToBorderRadius = true; |
|
334 |
} |
|
335 |
||
336 |
bool clippedWithLocalScrolling = hasOverflowClip() && bgLayer->attachment() == LocalBackgroundAttachment; |
|
337 |
if (clippedWithLocalScrolling) { |
|
338 |
// Clip to the overflow area. |
|
339 |
context->save(); |
|
340 |
context->clip(toRenderBox(this)->overflowClipRect(tx, ty)); |
|
341 |
||
342 |
// Now adjust our tx, ty, w, h to reflect a scrolled content box with borders at the ends. |
|
343 |
layer()->subtractScrolledContentOffset(tx, ty); |
|
344 |
w = bLeft + layer()->scrollWidth() + bRight; |
|
345 |
h = borderTop() + layer()->scrollHeight() + borderBottom(); |
|
346 |
} |
|
347 |
||
348 |
if (bgLayer->clip() == PaddingFillBox || bgLayer->clip() == ContentFillBox) { |
|
349 |
// Clip to the padding or content boxes as necessary. |
|
350 |
bool includePadding = bgLayer->clip() == ContentFillBox; |
|
351 |
int x = tx + bLeft + (includePadding ? pLeft : 0); |
|
352 |
int y = ty + borderTop() + (includePadding ? paddingTop() : 0); |
|
353 |
int width = w - bLeft - bRight - (includePadding ? pLeft + pRight : 0); |
|
354 |
int height = h - borderTop() - borderBottom() - (includePadding ? paddingTop() + paddingBottom() : 0); |
|
355 |
context->save(); |
|
356 |
context->clip(IntRect(x, y, width, height)); |
|
357 |
} else if (bgLayer->clip() == TextFillBox) { |
|
358 |
// We have to draw our text into a mask that can then be used to clip background drawing. |
|
359 |
// First figure out how big the mask has to be. It should be no bigger than what we need |
|
360 |
// to actually render, so we should intersect the dirty rect with the border box of the background. |
|
361 |
IntRect maskRect(tx, ty, w, h); |
|
362 |
maskRect.intersect(paintInfo.rect); |
|
363 |
||
364 |
// Now create the mask. |
|
365 |
OwnPtr<ImageBuffer> maskImage = ImageBuffer::create(maskRect.size()); |
|
366 |
if (!maskImage) |
|
367 |
return; |
|
368 |
||
369 |
GraphicsContext* maskImageContext = maskImage->context(); |
|
370 |
maskImageContext->translate(-maskRect.x(), -maskRect.y()); |
|
371 |
||
372 |
// Now add the text to the clip. We do this by painting using a special paint phase that signals to |
|
373 |
// InlineTextBoxes that they should just add their contents to the clip. |
|
374 |
PaintInfo info(maskImageContext, maskRect, PaintPhaseTextClip, true, 0, 0); |
|
375 |
if (box) |
|
376 |
box->paint(info, tx - box->x(), ty - box->y()); |
|
377 |
else { |
|
378 |
int x = isBox() ? toRenderBox(this)->x() : 0; |
|
379 |
int y = isBox() ? toRenderBox(this)->y() : 0; |
|
380 |
paint(info, tx - x, ty - y); |
|
381 |
} |
|
382 |
||
383 |
// The mask has been created. Now we just need to clip to it. |
|
384 |
context->save(); |
|
385 |
context->clipToImageBuffer(maskRect, maskImage.get()); |
|
386 |
} |
|
387 |
||
388 |
StyleImage* bg = bgLayer->image(); |
|
389 |
bool shouldPaintBackgroundImage = bg && bg->canRender(style()->effectiveZoom()); |
|
390 |
Color bgColor = c; |
|
391 |
||
392 |
// When this style flag is set, change existing background colors and images to a solid white background. |
|
393 |
// If there's no bg color or image, leave it untouched to avoid affecting transparency. |
|
394 |
// We don't try to avoid loading the background images, because this style flag is only set |
|
395 |
// when printing, and at that point we've already loaded the background images anyway. (To avoid |
|
396 |
// loading the background images we'd have to do this check when applying styles rather than |
|
397 |
// while rendering.) |
|
398 |
if (style()->forceBackgroundsToWhite()) { |
|
399 |
// Note that we can't reuse this variable below because the bgColor might be changed |
|
400 |
bool shouldPaintBackgroundColor = !bgLayer->next() && bgColor.isValid() && bgColor.alpha() > 0; |
|
401 |
if (shouldPaintBackgroundImage || shouldPaintBackgroundColor) { |
|
402 |
bgColor = Color::white; |
|
403 |
shouldPaintBackgroundImage = false; |
|
404 |
} |
|
405 |
} |
|
406 |
||
407 |
bool isRoot = this->isRoot(); |
|
408 |
||
409 |
// Only fill with a base color (e.g., white) if we're the root document, since iframes/frames with |
|
410 |
// no background in the child document should show the parent's background. |
|
411 |
bool isOpaqueRoot = false; |
|
412 |
if (isRoot) { |
|
413 |
isOpaqueRoot = true; |
|
414 |
if (!bgLayer->next() && !(bgColor.isValid() && bgColor.alpha() == 255) && view()->frameView()) { |
|
415 |
Element* ownerElement = document()->ownerElement(); |
|
416 |
if (ownerElement) { |
|
417 |
if (!ownerElement->hasTagName(frameTag)) { |
|
418 |
// Locate the <body> element using the DOM. This is easier than trying |
|
419 |
// to crawl around a render tree with potential :before/:after content and |
|
420 |
// anonymous blocks created by inline <body> tags etc. We can locate the <body> |
|
421 |
// render object very easily via the DOM. |
|
422 |
HTMLElement* body = document()->body(); |
|
423 |
if (body) { |
|
424 |
// Can't scroll a frameset document anyway. |
|
425 |
isOpaqueRoot = body->hasLocalName(framesetTag); |
|
426 |
} |
|
427 |
} |
|
428 |
} else |
|
429 |
isOpaqueRoot = !view()->frameView()->isTransparent(); |
|
430 |
} |
|
431 |
view()->frameView()->setContentIsOpaque(isOpaqueRoot); |
|
432 |
} |
|
433 |
||
434 |
// Paint the color first underneath all images. |
|
435 |
if (!bgLayer->next()) { |
|
436 |
IntRect rect(tx, ty, w, h); |
|
437 |
rect.intersect(paintInfo.rect); |
|
438 |
// If we have an alpha and we are painting the root element, go ahead and blend with the base background color. |
|
439 |
if (isOpaqueRoot) { |
|
440 |
Color baseColor = view()->frameView()->baseBackgroundColor(); |
|
441 |
if (baseColor.alpha() > 0) { |
|
442 |
context->save(); |
|
443 |
context->setCompositeOperation(CompositeCopy); |
|
444 |
context->fillRect(rect, baseColor); |
|
445 |
context->restore(); |
|
446 |
} else |
|
447 |
context->clearRect(rect); |
|
448 |
} |
|
449 |
||
450 |
if (bgColor.isValid() && bgColor.alpha() > 0) |
|
451 |
context->fillRect(rect, bgColor); |
|
452 |
} |
|
453 |
||
454 |
// no progressive loading of the background image |
|
455 |
if (shouldPaintBackgroundImage) { |
|
456 |
IntRect destRect; |
|
457 |
IntPoint phase; |
|
458 |
IntSize tileSize; |
|
459 |
||
460 |
calculateBackgroundImageGeometry(bgLayer, tx, ty, w, h, destRect, phase, tileSize); |
|
461 |
IntPoint destOrigin = destRect.location(); |
|
462 |
destRect.intersect(paintInfo.rect); |
|
463 |
if (!destRect.isEmpty()) { |
|
464 |
phase += destRect.location() - destOrigin; |
|
465 |
CompositeOperator compositeOp = op == CompositeSourceOver ? bgLayer->composite() : op; |
|
466 |
RenderObject* clientForBackgroundImage = this; |
|
467 |
// Check if this is the root element painting a background layer propagated from <body>, |
|
468 |
// and pass the body's renderer as the client in that case. |
|
469 |
if (isRoot && !style()->hasBackground()) { |
|
470 |
ASSERT(node()->hasTagName(htmlTag)); |
|
471 |
HTMLElement* body = document()->body(); |
|
472 |
ASSERT(body); |
|
473 |
ASSERT(body->hasLocalName(bodyTag)); |
|
474 |
ASSERT(body->renderer()); |
|
475 |
if (body) { |
|
476 |
if (RenderObject* bodyRenderer = body->renderer()) |
|
477 |
clientForBackgroundImage = bodyRenderer; |
|
478 |
} |
|
479 |
} |
|
480 |
context->drawTiledImage(bg->image(clientForBackgroundImage, tileSize), destRect, phase, tileSize, compositeOp); |
|
481 |
} |
|
482 |
} |
|
483 |
||
484 |
if (bgLayer->clip() != BorderFillBox) |
|
485 |
// Undo the background clip |
|
486 |
context->restore(); |
|
487 |
||
488 |
if (clippedToBorderRadius) |
|
489 |
// Undo the border radius clip |
|
490 |
context->restore(); |
|
491 |
||
492 |
if (clippedWithLocalScrolling) // Undo the clip for local background attachments. |
|
493 |
context->restore(); |
|
494 |
} |
|
495 |
||
496 |
IntSize RenderBoxModelObject::calculateFillTileSize(const FillLayer* fillLayer, IntSize positioningAreaSize) const |
|
497 |
{ |
|
498 |
StyleImage* image = fillLayer->image(); |
|
499 |
image->setImageContainerSize(positioningAreaSize); // Use the box established by background-origin. |
|
500 |
||
501 |
EFillSizeType type = fillLayer->size().type; |
|
502 |
||
503 |
switch (type) { |
|
504 |
case SizeLength: { |
|
505 |
int w = positioningAreaSize.width(); |
|
506 |
int h = positioningAreaSize.height(); |
|
507 |
Length layerWidth = fillLayer->size().size.width(); |
|
508 |
Length layerHeight = fillLayer->size().size.height(); |
|
509 |
||
510 |
if (layerWidth.isFixed()) |
|
511 |
w = layerWidth.value(); |
|
512 |
else if (layerWidth.isPercent()) |
|
513 |
w = layerWidth.calcValue(positioningAreaSize.width()); |
|
514 |
||
515 |
if (layerHeight.isFixed()) |
|
516 |
h = layerHeight.value(); |
|
517 |
else if (layerHeight.isPercent()) |
|
518 |
h = layerHeight.calcValue(positioningAreaSize.height()); |
|
519 |
||
520 |
// If one of the values is auto we have to use the appropriate |
|
521 |
// scale to maintain our aspect ratio. |
|
522 |
if (layerWidth.isAuto() && !layerHeight.isAuto()) |
|
523 |
w = image->imageSize(this, style()->effectiveZoom()).width() * h / image->imageSize(this, style()->effectiveZoom()).height(); |
|
524 |
else if (!layerWidth.isAuto() && layerHeight.isAuto()) |
|
525 |
h = image->imageSize(this, style()->effectiveZoom()).height() * w / image->imageSize(this, style()->effectiveZoom()).width(); |
|
526 |
else if (layerWidth.isAuto() && layerHeight.isAuto()) { |
|
527 |
// If both width and height are auto, we just want to use the image's |
|
528 |
// intrinsic size. |
|
529 |
w = image->imageSize(this, style()->effectiveZoom()).width(); |
|
530 |
h = image->imageSize(this, style()->effectiveZoom()).height(); |
|
531 |
} |
|
532 |
||
533 |
return IntSize(max(1, w), max(1, h)); |
|
534 |
} |
|
535 |
case Contain: |
|
536 |
case Cover: { |
|
537 |
IntSize imageIntrinsicSize = image->imageSize(this, 1); |
|
538 |
float horizontalScaleFactor = static_cast<float>(positioningAreaSize.width()) / imageIntrinsicSize.width(); |
|
539 |
float verticalScaleFactor = static_cast<float>(positioningAreaSize.height()) / imageIntrinsicSize.height(); |
|
540 |
float scaleFactor = type == Contain ? min(horizontalScaleFactor, verticalScaleFactor) : max(horizontalScaleFactor, verticalScaleFactor); |
|
541 |
||
542 |
return IntSize(max<int>(1, imageIntrinsicSize.width() * scaleFactor), max<int>(1, imageIntrinsicSize.height() * scaleFactor)); |
|
543 |
} |
|
544 |
case SizeNone: |
|
545 |
break; |
|
546 |
} |
|
547 |
return image->imageSize(this, style()->effectiveZoom()); |
|
548 |
} |
|
549 |
||
550 |
void RenderBoxModelObject::calculateBackgroundImageGeometry(const FillLayer* fillLayer, int tx, int ty, int w, int h, |
|
551 |
IntRect& destRect, IntPoint& phase, IntSize& tileSize) |
|
552 |
{ |
|
553 |
int left = 0; |
|
554 |
int top = 0; |
|
555 |
IntSize positioningAreaSize; |
|
556 |
||
557 |
// Determine the background positioning area and set destRect to the background painting area. |
|
558 |
// destRect will be adjusted later if the background is non-repeating. |
|
559 |
bool fixedAttachment = fillLayer->attachment() == FixedBackgroundAttachment; |
|
19
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
560 |
|
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
561 |
#if ENABLE(FAST_MOBILE_SCROLLING) |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
562 |
if (view()->frameView() && view()->frameView()->canBlitOnScroll()) { |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
563 |
// As a side effect of an optimization to blit on scroll, we do not honor the CSS |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
564 |
// property "background-attachment: fixed" because it may result in rendering |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
565 |
// artifacts. Note, these artifacts only appear if we are blitting on scroll of |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
566 |
// a page that has fixed background images. |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
567 |
fixedAttachment = false; |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
568 |
} |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
569 |
#endif |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
570 |
|
0 | 571 |
if (!fixedAttachment) { |
572 |
destRect = IntRect(tx, ty, w, h); |
|
573 |
||
574 |
int right = 0; |
|
575 |
int bottom = 0; |
|
576 |
// Scroll and Local. |
|
577 |
if (fillLayer->origin() != BorderFillBox) { |
|
578 |
left = borderLeft(); |
|
579 |
right = borderRight(); |
|
580 |
top = borderTop(); |
|
581 |
bottom = borderBottom(); |
|
582 |
if (fillLayer->origin() == ContentFillBox) { |
|
583 |
left += paddingLeft(); |
|
584 |
right += paddingRight(); |
|
585 |
top += paddingTop(); |
|
586 |
bottom += paddingBottom(); |
|
587 |
} |
|
588 |
} |
|
589 |
||
590 |
// The background of the box generated by the root element covers the entire canvas including |
|
591 |
// its margins. Since those were added in already, we have to factor them out when computing |
|
592 |
// the background positioning area. |
|
593 |
if (isRoot()) { |
|
594 |
positioningAreaSize = IntSize(toRenderBox(this)->width() - left - right, toRenderBox(this)->height() - top - bottom); |
|
595 |
left += marginLeft(); |
|
596 |
top += marginTop(); |
|
597 |
} else |
|
598 |
positioningAreaSize = IntSize(w - left - right, h - top - bottom); |
|
599 |
} else { |
|
600 |
destRect = viewRect(); |
|
601 |
positioningAreaSize = destRect.size(); |
|
602 |
} |
|
603 |
||
604 |
tileSize = calculateFillTileSize(fillLayer, positioningAreaSize); |
|
605 |
||
606 |
EFillRepeat backgroundRepeatX = fillLayer->repeatX(); |
|
607 |
EFillRepeat backgroundRepeatY = fillLayer->repeatY(); |
|
608 |
||
609 |
int xPosition = fillLayer->xPosition().calcMinValue(positioningAreaSize.width() - tileSize.width(), true); |
|
610 |
if (backgroundRepeatX == RepeatFill) |
|
611 |
phase.setX(tileSize.width() ? tileSize.width() - (xPosition + left) % tileSize.width() : 0); |
|
612 |
else { |
|
613 |
destRect.move(max(xPosition + left, 0), 0); |
|
614 |
phase.setX(-min(xPosition + left, 0)); |
|
615 |
destRect.setWidth(tileSize.width() + min(xPosition + left, 0)); |
|
616 |
} |
|
617 |
||
618 |
int yPosition = fillLayer->yPosition().calcMinValue(positioningAreaSize.height() - tileSize.height(), true); |
|
619 |
if (backgroundRepeatY == RepeatFill) |
|
620 |
phase.setY(tileSize.height() ? tileSize.height() - (yPosition + top) % tileSize.height() : 0); |
|
621 |
else { |
|
622 |
destRect.move(0, max(yPosition + top, 0)); |
|
623 |
phase.setY(-min(yPosition + top, 0)); |
|
624 |
destRect.setHeight(tileSize.height() + min(yPosition + top, 0)); |
|
625 |
} |
|
626 |
||
627 |
if (fixedAttachment) |
|
628 |
phase.move(max(tx - destRect.x(), 0), max(ty - destRect.y(), 0)); |
|
629 |
||
630 |
destRect.intersect(IntRect(tx, ty, w, h)); |
|
631 |
} |
|
632 |
||
633 |
int RenderBoxModelObject::verticalPosition(bool firstLine) const |
|
634 |
{ |
|
635 |
// This method determines the vertical position for inline elements. |
|
636 |
ASSERT(isInline()); |
|
637 |
if (!isInline()) |
|
638 |
return 0; |
|
639 |
||
640 |
int vpos = 0; |
|
641 |
EVerticalAlign va = style()->verticalAlign(); |
|
642 |
if (va == TOP) |
|
643 |
vpos = PositionTop; |
|
644 |
else if (va == BOTTOM) |
|
645 |
vpos = PositionBottom; |
|
646 |
else { |
|
647 |
bool checkParent = parent()->isRenderInline() && parent()->style()->verticalAlign() != TOP && parent()->style()->verticalAlign() != BOTTOM; |
|
648 |
vpos = checkParent ? toRenderInline(parent())->verticalPositionFromCache(firstLine) : 0; |
|
649 |
// don't allow elements nested inside text-top to have a different valignment. |
|
650 |
if (va == BASELINE) |
|
651 |
return vpos; |
|
652 |
||
653 |
const Font& f = parent()->style(firstLine)->font(); |
|
654 |
int fontsize = f.pixelSize(); |
|
655 |
||
656 |
if (va == SUB) |
|
657 |
vpos += fontsize / 5 + 1; |
|
658 |
else if (va == SUPER) |
|
659 |
vpos -= fontsize / 3 + 1; |
|
660 |
else if (va == TEXT_TOP) |
|
661 |
vpos += baselinePosition(firstLine) - f.ascent(); |
|
662 |
else if (va == MIDDLE) |
|
663 |
vpos += -static_cast<int>(f.xHeight() / 2) - lineHeight(firstLine) / 2 + baselinePosition(firstLine); |
|
664 |
else if (va == TEXT_BOTTOM) { |
|
665 |
vpos += f.descent(); |
|
666 |
if (!isReplaced()) // lineHeight - baselinePosition is always 0 for replaced elements, so don't bother wasting time in that case. |
|
667 |
vpos -= (lineHeight(firstLine) - baselinePosition(firstLine)); |
|
668 |
} else if (va == BASELINE_MIDDLE) |
|
669 |
vpos += -lineHeight(firstLine) / 2 + baselinePosition(firstLine); |
|
670 |
else if (va == LENGTH) |
|
671 |
vpos -= style()->verticalAlignLength().calcValue(lineHeight(firstLine)); |
|
672 |
} |
|
673 |
||
674 |
return vpos; |
|
675 |
} |
|
676 |
||
677 |
bool RenderBoxModelObject::paintNinePieceImage(GraphicsContext* graphicsContext, int tx, int ty, int w, int h, const RenderStyle* style, |
|
678 |
const NinePieceImage& ninePieceImage, CompositeOperator op) |
|
679 |
{ |
|
680 |
StyleImage* styleImage = ninePieceImage.image(); |
|
681 |
if (!styleImage) |
|
682 |
return false; |
|
683 |
||
684 |
if (!styleImage->isLoaded()) |
|
685 |
return true; // Never paint a nine-piece image incrementally, but don't paint the fallback borders either. |
|
686 |
||
687 |
if (!styleImage->canRender(style->effectiveZoom())) |
|
688 |
return false; |
|
689 |
||
690 |
// FIXME: border-image is broken with full page zooming when tiling has to happen, since the tiling function |
|
691 |
// doesn't have any understanding of the zoom that is in effect on the tile. |
|
692 |
styleImage->setImageContainerSize(IntSize(w, h)); |
|
693 |
IntSize imageSize = styleImage->imageSize(this, 1.0f); |
|
694 |
int imageWidth = imageSize.width(); |
|
695 |
int imageHeight = imageSize.height(); |
|
696 |
||
697 |
int topSlice = min(imageHeight, ninePieceImage.m_slices.top().calcValue(imageHeight)); |
|
698 |
int bottomSlice = min(imageHeight, ninePieceImage.m_slices.bottom().calcValue(imageHeight)); |
|
699 |
int leftSlice = min(imageWidth, ninePieceImage.m_slices.left().calcValue(imageWidth)); |
|
700 |
int rightSlice = min(imageWidth, ninePieceImage.m_slices.right().calcValue(imageWidth)); |
|
701 |
||
702 |
ENinePieceImageRule hRule = ninePieceImage.horizontalRule(); |
|
703 |
ENinePieceImageRule vRule = ninePieceImage.verticalRule(); |
|
704 |
||
705 |
bool fitToBorder = style->borderImage() == ninePieceImage; |
|
706 |
||
707 |
int leftWidth = fitToBorder ? style->borderLeftWidth() : leftSlice; |
|
708 |
int topWidth = fitToBorder ? style->borderTopWidth() : topSlice; |
|
709 |
int rightWidth = fitToBorder ? style->borderRightWidth() : rightSlice; |
|
710 |
int bottomWidth = fitToBorder ? style->borderBottomWidth() : bottomSlice; |
|
711 |
||
712 |
bool drawLeft = leftSlice > 0 && leftWidth > 0; |
|
713 |
bool drawTop = topSlice > 0 && topWidth > 0; |
|
714 |
bool drawRight = rightSlice > 0 && rightWidth > 0; |
|
715 |
bool drawBottom = bottomSlice > 0 && bottomWidth > 0; |
|
716 |
bool drawMiddle = (imageWidth - leftSlice - rightSlice) > 0 && (w - leftWidth - rightWidth) > 0 && |
|
717 |
(imageHeight - topSlice - bottomSlice) > 0 && (h - topWidth - bottomWidth) > 0; |
|
718 |
||
719 |
Image* image = styleImage->image(this, imageSize); |
|
720 |
||
721 |
if (drawLeft) { |
|
722 |
// Paint the top and bottom left corners. |
|
723 |
||
724 |
// The top left corner rect is (tx, ty, leftWidth, topWidth) |
|
725 |
// The rect to use from within the image is obtained from our slice, and is (0, 0, leftSlice, topSlice) |
|
726 |
if (drawTop) |
|
727 |
graphicsContext->drawImage(image, IntRect(tx, ty, leftWidth, topWidth), |
|
728 |
IntRect(0, 0, leftSlice, topSlice), op); |
|
729 |
||
730 |
// The bottom left corner rect is (tx, ty + h - bottomWidth, leftWidth, bottomWidth) |
|
731 |
// The rect to use from within the image is (0, imageHeight - bottomSlice, leftSlice, botomSlice) |
|
732 |
if (drawBottom) |
|
733 |
graphicsContext->drawImage(image, IntRect(tx, ty + h - bottomWidth, leftWidth, bottomWidth), |
|
734 |
IntRect(0, imageHeight - bottomSlice, leftSlice, bottomSlice), op); |
|
735 |
||
736 |
// Paint the left edge. |
|
737 |
// Have to scale and tile into the border rect. |
|
738 |
graphicsContext->drawTiledImage(image, IntRect(tx, ty + topWidth, leftWidth, |
|
739 |
h - topWidth - bottomWidth), |
|
740 |
IntRect(0, topSlice, leftSlice, imageHeight - topSlice - bottomSlice), |
|
741 |
Image::StretchTile, (Image::TileRule)vRule, op); |
|
742 |
} |
|
743 |
||
744 |
if (drawRight) { |
|
745 |
// Paint the top and bottom right corners |
|
746 |
// The top right corner rect is (tx + w - rightWidth, ty, rightWidth, topWidth) |
|
747 |
// The rect to use from within the image is obtained from our slice, and is (imageWidth - rightSlice, 0, rightSlice, topSlice) |
|
748 |
if (drawTop) |
|
749 |
graphicsContext->drawImage(image, IntRect(tx + w - rightWidth, ty, rightWidth, topWidth), |
|
750 |
IntRect(imageWidth - rightSlice, 0, rightSlice, topSlice), op); |
|
751 |
||
752 |
// The bottom right corner rect is (tx + w - rightWidth, ty + h - bottomWidth, rightWidth, bottomWidth) |
|
753 |
// The rect to use from within the image is (imageWidth - rightSlice, imageHeight - bottomSlice, rightSlice, bottomSlice) |
|
754 |
if (drawBottom) |
|
755 |
graphicsContext->drawImage(image, IntRect(tx + w - rightWidth, ty + h - bottomWidth, rightWidth, bottomWidth), |
|
756 |
IntRect(imageWidth - rightSlice, imageHeight - bottomSlice, rightSlice, bottomSlice), op); |
|
757 |
||
758 |
// Paint the right edge. |
|
759 |
graphicsContext->drawTiledImage(image, IntRect(tx + w - rightWidth, ty + topWidth, rightWidth, |
|
760 |
h - topWidth - bottomWidth), |
|
761 |
IntRect(imageWidth - rightSlice, topSlice, rightSlice, imageHeight - topSlice - bottomSlice), |
|
762 |
Image::StretchTile, (Image::TileRule)vRule, op); |
|
763 |
} |
|
764 |
||
765 |
// Paint the top edge. |
|
766 |
if (drawTop) |
|
767 |
graphicsContext->drawTiledImage(image, IntRect(tx + leftWidth, ty, w - leftWidth - rightWidth, topWidth), |
|
768 |
IntRect(leftSlice, 0, imageWidth - rightSlice - leftSlice, topSlice), |
|
769 |
(Image::TileRule)hRule, Image::StretchTile, op); |
|
770 |
||
771 |
// Paint the bottom edge. |
|
772 |
if (drawBottom) |
|
773 |
graphicsContext->drawTiledImage(image, IntRect(tx + leftWidth, ty + h - bottomWidth, |
|
774 |
w - leftWidth - rightWidth, bottomWidth), |
|
775 |
IntRect(leftSlice, imageHeight - bottomSlice, imageWidth - rightSlice - leftSlice, bottomSlice), |
|
776 |
(Image::TileRule)hRule, Image::StretchTile, op); |
|
777 |
||
778 |
// Paint the middle. |
|
779 |
if (drawMiddle) |
|
780 |
graphicsContext->drawTiledImage(image, IntRect(tx + leftWidth, ty + topWidth, w - leftWidth - rightWidth, |
|
781 |
h - topWidth - bottomWidth), |
|
782 |
IntRect(leftSlice, topSlice, imageWidth - rightSlice - leftSlice, imageHeight - topSlice - bottomSlice), |
|
783 |
(Image::TileRule)hRule, (Image::TileRule)vRule, op); |
|
784 |
||
785 |
return true; |
|
786 |
} |
|
787 |
||
788 |
void RenderBoxModelObject::paintBorder(GraphicsContext* graphicsContext, int tx, int ty, int w, int h, |
|
789 |
const RenderStyle* style, bool begin, bool end) |
|
790 |
{ |
|
791 |
if (paintNinePieceImage(graphicsContext, tx, ty, w, h, style, style->borderImage())) |
|
792 |
return; |
|
793 |
||
794 |
const Color& topColor = style->borderTopColor(); |
|
795 |
const Color& bottomColor = style->borderBottomColor(); |
|
796 |
const Color& leftColor = style->borderLeftColor(); |
|
797 |
const Color& rightColor = style->borderRightColor(); |
|
798 |
||
799 |
bool topTransparent = style->borderTopIsTransparent(); |
|
800 |
bool bottomTransparent = style->borderBottomIsTransparent(); |
|
801 |
bool rightTransparent = style->borderRightIsTransparent(); |
|
802 |
bool leftTransparent = style->borderLeftIsTransparent(); |
|
803 |
||
804 |
EBorderStyle topStyle = style->borderTopStyle(); |
|
805 |
EBorderStyle bottomStyle = style->borderBottomStyle(); |
|
806 |
EBorderStyle leftStyle = style->borderLeftStyle(); |
|
807 |
EBorderStyle rightStyle = style->borderRightStyle(); |
|
808 |
||
809 |
bool renderTop = topStyle > BHIDDEN && !topTransparent; |
|
810 |
bool renderLeft = leftStyle > BHIDDEN && begin && !leftTransparent; |
|
811 |
bool renderRight = rightStyle > BHIDDEN && end && !rightTransparent; |
|
812 |
bool renderBottom = bottomStyle > BHIDDEN && !bottomTransparent; |
|
813 |
||
814 |
bool renderRadii = false; |
|
815 |
IntSize topLeft, topRight, bottomLeft, bottomRight; |
|
816 |
||
817 |
if (style->hasBorderRadius()) { |
|
818 |
IntRect borderRect = IntRect(tx, ty, w, h); |
|
819 |
||
820 |
IntSize topLeftRadius, topRightRadius, bottomLeftRadius, bottomRightRadius; |
|
821 |
style->getBorderRadiiForRect(borderRect, topLeftRadius, topRightRadius, bottomLeftRadius, bottomRightRadius); |
|
822 |
||
823 |
if (begin) { |
|
824 |
topLeft = topLeftRadius; |
|
825 |
bottomLeft = bottomLeftRadius; |
|
826 |
} |
|
827 |
if (end) { |
|
828 |
topRight = topRightRadius; |
|
829 |
bottomRight = bottomRightRadius; |
|
830 |
} |
|
831 |
||
832 |
renderRadii = true; |
|
833 |
||
834 |
// Clip to the rounded rectangle. |
|
835 |
graphicsContext->save(); |
|
836 |
graphicsContext->addRoundedRectClip(borderRect, topLeft, topRight, bottomLeft, bottomRight); |
|
837 |
} |
|
838 |
||
839 |
int firstAngleStart, secondAngleStart, firstAngleSpan, secondAngleSpan; |
|
840 |
float thickness; |
|
841 |
bool upperLeftBorderStylesMatch = renderLeft && (topStyle == leftStyle) && (topColor == leftColor); |
|
842 |
bool upperRightBorderStylesMatch = renderRight && (topStyle == rightStyle) && (topColor == rightColor) && (topStyle != OUTSET) && (topStyle != RIDGE) && (topStyle != INSET) && (topStyle != GROOVE); |
|
843 |
bool lowerLeftBorderStylesMatch = renderLeft && (bottomStyle == leftStyle) && (bottomColor == leftColor) && (bottomStyle != OUTSET) && (bottomStyle != RIDGE) && (bottomStyle != INSET) && (bottomStyle != GROOVE); |
|
844 |
bool lowerRightBorderStylesMatch = renderRight && (bottomStyle == rightStyle) && (bottomColor == rightColor); |
|
845 |
||
846 |
if (renderTop) { |
|
847 |
bool ignore_left = (renderRadii && topLeft.width() > 0) || |
|
848 |
(topColor == leftColor && topTransparent == leftTransparent && topStyle >= OUTSET && |
|
849 |
(leftStyle == DOTTED || leftStyle == DASHED || leftStyle == SOLID || leftStyle == OUTSET)); |
|
850 |
||
851 |
bool ignore_right = (renderRadii && topRight.width() > 0) || |
|
852 |
(topColor == rightColor && topTransparent == rightTransparent && topStyle >= OUTSET && |
|
853 |
(rightStyle == DOTTED || rightStyle == DASHED || rightStyle == SOLID || rightStyle == INSET)); |
|
854 |
||
855 |
int x = tx; |
|
856 |
int x2 = tx + w; |
|
857 |
if (renderRadii) { |
|
858 |
x += topLeft.width(); |
|
859 |
x2 -= topRight.width(); |
|
860 |
} |
|
861 |
||
862 |
drawLineForBoxSide(graphicsContext, x, ty, x2, ty + style->borderTopWidth(), BSTop, topColor, style->color(), topStyle, |
|
863 |
ignore_left ? 0 : style->borderLeftWidth(), ignore_right ? 0 : style->borderRightWidth()); |
|
864 |
||
865 |
if (renderRadii) { |
|
866 |
int leftY = ty; |
|
867 |
||
868 |
// We make the arc double thick and let the clip rect take care of clipping the extra off. |
|
869 |
// We're doing this because it doesn't seem possible to match the curve of the clip exactly |
|
870 |
// with the arc-drawing function. |
|
871 |
thickness = style->borderTopWidth() * 2; |
|
872 |
||
873 |
if (topLeft.width()) { |
|
874 |
int leftX = tx; |
|
875 |
// The inner clip clips inside the arc. This is especially important for 1px borders. |
|
876 |
bool applyLeftInnerClip = (style->borderLeftWidth() < topLeft.width()) |
|
877 |
&& (style->borderTopWidth() < topLeft.height()) |
|
878 |
&& (topStyle != DOUBLE || style->borderTopWidth() > 6); |
|
879 |
if (applyLeftInnerClip) { |
|
880 |
graphicsContext->save(); |
|
881 |
graphicsContext->addInnerRoundedRectClip(IntRect(leftX, leftY, topLeft.width() * 2, topLeft.height() * 2), |
|
882 |
style->borderTopWidth()); |
|
883 |
} |
|
884 |
||
885 |
firstAngleStart = 90; |
|
886 |
firstAngleSpan = upperLeftBorderStylesMatch ? 90 : 45; |
|
887 |
||
888 |
// Draw upper left arc |
|
889 |
drawArcForBoxSide(graphicsContext, leftX, leftY, thickness, topLeft, firstAngleStart, firstAngleSpan, |
|
890 |
BSTop, topColor, style->color(), topStyle, true); |
|
891 |
if (applyLeftInnerClip) |
|
892 |
graphicsContext->restore(); |
|
893 |
} |
|
894 |
||
895 |
if (topRight.width()) { |
|
896 |
int rightX = tx + w - topRight.width() * 2; |
|
897 |
bool applyRightInnerClip = (style->borderRightWidth() < topRight.width()) |
|
898 |
&& (style->borderTopWidth() < topRight.height()) |
|
899 |
&& (topStyle != DOUBLE || style->borderTopWidth() > 6); |
|
900 |
if (applyRightInnerClip) { |
|
901 |
graphicsContext->save(); |
|
902 |
graphicsContext->addInnerRoundedRectClip(IntRect(rightX, leftY, topRight.width() * 2, topRight.height() * 2), |
|
903 |
style->borderTopWidth()); |
|
904 |
} |
|
905 |
||
906 |
if (upperRightBorderStylesMatch) { |
|
907 |
secondAngleStart = 0; |
|
908 |
secondAngleSpan = 90; |
|
909 |
} else { |
|
910 |
secondAngleStart = 45; |
|
911 |
secondAngleSpan = 45; |
|
912 |
} |
|
913 |
||
914 |
// Draw upper right arc |
|
915 |
drawArcForBoxSide(graphicsContext, rightX, leftY, thickness, topRight, secondAngleStart, secondAngleSpan, |
|
916 |
BSTop, topColor, style->color(), topStyle, false); |
|
917 |
if (applyRightInnerClip) |
|
918 |
graphicsContext->restore(); |
|
919 |
} |
|
920 |
} |
|
921 |
} |
|
922 |
||
923 |
if (renderBottom) { |
|
924 |
bool ignore_left = (renderRadii && bottomLeft.width() > 0) || |
|
925 |
(bottomColor == leftColor && bottomTransparent == leftTransparent && bottomStyle >= OUTSET && |
|
926 |
(leftStyle == DOTTED || leftStyle == DASHED || leftStyle == SOLID || leftStyle == OUTSET)); |
|
927 |
||
928 |
bool ignore_right = (renderRadii && bottomRight.width() > 0) || |
|
929 |
(bottomColor == rightColor && bottomTransparent == rightTransparent && bottomStyle >= OUTSET && |
|
930 |
(rightStyle == DOTTED || rightStyle == DASHED || rightStyle == SOLID || rightStyle == INSET)); |
|
931 |
||
932 |
int x = tx; |
|
933 |
int x2 = tx + w; |
|
934 |
if (renderRadii) { |
|
935 |
x += bottomLeft.width(); |
|
936 |
x2 -= bottomRight.width(); |
|
937 |
} |
|
938 |
||
939 |
drawLineForBoxSide(graphicsContext, x, ty + h - style->borderBottomWidth(), x2, ty + h, BSBottom, bottomColor, style->color(), bottomStyle, |
|
940 |
ignore_left ? 0 : style->borderLeftWidth(), ignore_right ? 0 : style->borderRightWidth()); |
|
941 |
||
942 |
if (renderRadii) { |
|
943 |
thickness = style->borderBottomWidth() * 2; |
|
944 |
||
945 |
if (bottomLeft.width()) { |
|
946 |
int leftX = tx; |
|
947 |
int leftY = ty + h - bottomLeft.height() * 2; |
|
948 |
bool applyLeftInnerClip = (style->borderLeftWidth() < bottomLeft.width()) |
|
949 |
&& (style->borderBottomWidth() < bottomLeft.height()) |
|
950 |
&& (bottomStyle != DOUBLE || style->borderBottomWidth() > 6); |
|
951 |
if (applyLeftInnerClip) { |
|
952 |
graphicsContext->save(); |
|
953 |
graphicsContext->addInnerRoundedRectClip(IntRect(leftX, leftY, bottomLeft.width() * 2, bottomLeft.height() * 2), |
|
954 |
style->borderBottomWidth()); |
|
955 |
} |
|
956 |
||
957 |
if (lowerLeftBorderStylesMatch) { |
|
958 |
firstAngleStart = 180; |
|
959 |
firstAngleSpan = 90; |
|
960 |
} else { |
|
961 |
firstAngleStart = 225; |
|
962 |
firstAngleSpan = 45; |
|
963 |
} |
|
964 |
||
965 |
// Draw lower left arc |
|
966 |
drawArcForBoxSide(graphicsContext, leftX, leftY, thickness, bottomLeft, firstAngleStart, firstAngleSpan, |
|
967 |
BSBottom, bottomColor, style->color(), bottomStyle, true); |
|
968 |
if (applyLeftInnerClip) |
|
969 |
graphicsContext->restore(); |
|
970 |
} |
|
971 |
||
972 |
if (bottomRight.width()) { |
|
973 |
int rightY = ty + h - bottomRight.height() * 2; |
|
974 |
int rightX = tx + w - bottomRight.width() * 2; |
|
975 |
bool applyRightInnerClip = (style->borderRightWidth() < bottomRight.width()) |
|
976 |
&& (style->borderBottomWidth() < bottomRight.height()) |
|
977 |
&& (bottomStyle != DOUBLE || style->borderBottomWidth() > 6); |
|
978 |
if (applyRightInnerClip) { |
|
979 |
graphicsContext->save(); |
|
980 |
graphicsContext->addInnerRoundedRectClip(IntRect(rightX, rightY, bottomRight.width() * 2, bottomRight.height() * 2), |
|
981 |
style->borderBottomWidth()); |
|
982 |
} |
|
983 |
||
984 |
secondAngleStart = 270; |
|
985 |
secondAngleSpan = lowerRightBorderStylesMatch ? 90 : 45; |
|
986 |
||
987 |
// Draw lower right arc |
|
988 |
drawArcForBoxSide(graphicsContext, rightX, rightY, thickness, bottomRight, secondAngleStart, secondAngleSpan, |
|
989 |
BSBottom, bottomColor, style->color(), bottomStyle, false); |
|
990 |
if (applyRightInnerClip) |
|
991 |
graphicsContext->restore(); |
|
992 |
} |
|
993 |
} |
|
994 |
} |
|
995 |
||
996 |
if (renderLeft) { |
|
997 |
bool ignore_top = (renderRadii && topLeft.height() > 0) || |
|
998 |
(topColor == leftColor && topTransparent == leftTransparent && leftStyle >= OUTSET && |
|
999 |
(topStyle == DOTTED || topStyle == DASHED || topStyle == SOLID || topStyle == OUTSET)); |
|
1000 |
||
1001 |
bool ignore_bottom = (renderRadii && bottomLeft.height() > 0) || |
|
1002 |
(bottomColor == leftColor && bottomTransparent == leftTransparent && leftStyle >= OUTSET && |
|
1003 |
(bottomStyle == DOTTED || bottomStyle == DASHED || bottomStyle == SOLID || bottomStyle == INSET)); |
|
1004 |
||
1005 |
int y = ty; |
|
1006 |
int y2 = ty + h; |
|
1007 |
if (renderRadii) { |
|
1008 |
y += topLeft.height(); |
|
1009 |
y2 -= bottomLeft.height(); |
|
1010 |
} |
|
1011 |
||
1012 |
drawLineForBoxSide(graphicsContext, tx, y, tx + style->borderLeftWidth(), y2, BSLeft, leftColor, style->color(), leftStyle, |
|
1013 |
ignore_top ? 0 : style->borderTopWidth(), ignore_bottom ? 0 : style->borderBottomWidth()); |
|
1014 |
||
1015 |
if (renderRadii && (!upperLeftBorderStylesMatch || !lowerLeftBorderStylesMatch)) { |
|
1016 |
int topX = tx; |
|
1017 |
thickness = style->borderLeftWidth() * 2; |
|
1018 |
||
1019 |
if (!upperLeftBorderStylesMatch && topLeft.width()) { |
|
1020 |
int topY = ty; |
|
1021 |
bool applyTopInnerClip = (style->borderLeftWidth() < topLeft.width()) |
|
1022 |
&& (style->borderTopWidth() < topLeft.height()) |
|
1023 |
&& (leftStyle != DOUBLE || style->borderLeftWidth() > 6); |
|
1024 |
if (applyTopInnerClip) { |
|
1025 |
graphicsContext->save(); |
|
1026 |
graphicsContext->addInnerRoundedRectClip(IntRect(topX, topY, topLeft.width() * 2, topLeft.height() * 2), |
|
1027 |
style->borderLeftWidth()); |
|
1028 |
} |
|
1029 |
||
1030 |
firstAngleStart = 135; |
|
1031 |
firstAngleSpan = 45; |
|
1032 |
||
1033 |
// Draw top left arc |
|
1034 |
drawArcForBoxSide(graphicsContext, topX, topY, thickness, topLeft, firstAngleStart, firstAngleSpan, |
|
1035 |
BSLeft, leftColor, style->color(), leftStyle, true); |
|
1036 |
if (applyTopInnerClip) |
|
1037 |
graphicsContext->restore(); |
|
1038 |
} |
|
1039 |
||
1040 |
if (!lowerLeftBorderStylesMatch && bottomLeft.width()) { |
|
1041 |
int bottomY = ty + h - bottomLeft.height() * 2; |
|
1042 |
bool applyBottomInnerClip = (style->borderLeftWidth() < bottomLeft.width()) |
|
1043 |
&& (style->borderBottomWidth() < bottomLeft.height()) |
|
1044 |
&& (leftStyle != DOUBLE || style->borderLeftWidth() > 6); |
|
1045 |
if (applyBottomInnerClip) { |
|
1046 |
graphicsContext->save(); |
|
1047 |
graphicsContext->addInnerRoundedRectClip(IntRect(topX, bottomY, bottomLeft.width() * 2, bottomLeft.height() * 2), |
|
1048 |
style->borderLeftWidth()); |
|
1049 |
} |
|
1050 |
||
1051 |
secondAngleStart = 180; |
|
1052 |
secondAngleSpan = 45; |
|
1053 |
||
1054 |
// Draw bottom left arc |
|
1055 |
drawArcForBoxSide(graphicsContext, topX, bottomY, thickness, bottomLeft, secondAngleStart, secondAngleSpan, |
|
1056 |
BSLeft, leftColor, style->color(), leftStyle, false); |
|
1057 |
if (applyBottomInnerClip) |
|
1058 |
graphicsContext->restore(); |
|
1059 |
} |
|
1060 |
} |
|
1061 |
} |
|
1062 |
||
1063 |
if (renderRight) { |
|
1064 |
bool ignore_top = (renderRadii && topRight.height() > 0) || |
|
1065 |
((topColor == rightColor) && (topTransparent == rightTransparent) && |
|
1066 |
(rightStyle >= DOTTED || rightStyle == INSET) && |
|
1067 |
(topStyle == DOTTED || topStyle == DASHED || topStyle == SOLID || topStyle == OUTSET)); |
|
1068 |
||
1069 |
bool ignore_bottom = (renderRadii && bottomRight.height() > 0) || |
|
1070 |
((bottomColor == rightColor) && (bottomTransparent == rightTransparent) && |
|
1071 |
(rightStyle >= DOTTED || rightStyle == INSET) && |
|
1072 |
(bottomStyle == DOTTED || bottomStyle == DASHED || bottomStyle == SOLID || bottomStyle == INSET)); |
|
1073 |
||
1074 |
int y = ty; |
|
1075 |
int y2 = ty + h; |
|
1076 |
if (renderRadii) { |
|
1077 |
y += topRight.height(); |
|
1078 |
y2 -= bottomRight.height(); |
|
1079 |
} |
|
1080 |
||
1081 |
drawLineForBoxSide(graphicsContext, tx + w - style->borderRightWidth(), y, tx + w, y2, BSRight, rightColor, style->color(), rightStyle, |
|
1082 |
ignore_top ? 0 : style->borderTopWidth(), ignore_bottom ? 0 : style->borderBottomWidth()); |
|
1083 |
||
1084 |
if (renderRadii && (!upperRightBorderStylesMatch || !lowerRightBorderStylesMatch)) { |
|
1085 |
thickness = style->borderRightWidth() * 2; |
|
1086 |
||
1087 |
if (!upperRightBorderStylesMatch && topRight.width()) { |
|
1088 |
int topX = tx + w - topRight.width() * 2; |
|
1089 |
int topY = ty; |
|
1090 |
bool applyTopInnerClip = (style->borderRightWidth() < topRight.width()) |
|
1091 |
&& (style->borderTopWidth() < topRight.height()) |
|
1092 |
&& (rightStyle != DOUBLE || style->borderRightWidth() > 6); |
|
1093 |
if (applyTopInnerClip) { |
|
1094 |
graphicsContext->save(); |
|
1095 |
graphicsContext->addInnerRoundedRectClip(IntRect(topX, topY, topRight.width() * 2, topRight.height() * 2), |
|
1096 |
style->borderRightWidth()); |
|
1097 |
} |
|
1098 |
||
1099 |
firstAngleStart = 0; |
|
1100 |
firstAngleSpan = 45; |
|
1101 |
||
1102 |
// Draw top right arc |
|
1103 |
drawArcForBoxSide(graphicsContext, topX, topY, thickness, topRight, firstAngleStart, firstAngleSpan, |
|
1104 |
BSRight, rightColor, style->color(), rightStyle, true); |
|
1105 |
if (applyTopInnerClip) |
|
1106 |
graphicsContext->restore(); |
|
1107 |
} |
|
1108 |
||
1109 |
if (!lowerRightBorderStylesMatch && bottomRight.width()) { |
|
1110 |
int bottomX = tx + w - bottomRight.width() * 2; |
|
1111 |
int bottomY = ty + h - bottomRight.height() * 2; |
|
1112 |
bool applyBottomInnerClip = (style->borderRightWidth() < bottomRight.width()) |
|
1113 |
&& (style->borderBottomWidth() < bottomRight.height()) |
|
1114 |
&& (rightStyle != DOUBLE || style->borderRightWidth() > 6); |
|
1115 |
if (applyBottomInnerClip) { |
|
1116 |
graphicsContext->save(); |
|
1117 |
graphicsContext->addInnerRoundedRectClip(IntRect(bottomX, bottomY, bottomRight.width() * 2, bottomRight.height() * 2), |
|
1118 |
style->borderRightWidth()); |
|
1119 |
} |
|
1120 |
||
1121 |
secondAngleStart = 315; |
|
1122 |
secondAngleSpan = 45; |
|
1123 |
||
1124 |
// Draw bottom right arc |
|
1125 |
drawArcForBoxSide(graphicsContext, bottomX, bottomY, thickness, bottomRight, secondAngleStart, secondAngleSpan, |
|
1126 |
BSRight, rightColor, style->color(), rightStyle, false); |
|
1127 |
if (applyBottomInnerClip) |
|
1128 |
graphicsContext->restore(); |
|
1129 |
} |
|
1130 |
} |
|
1131 |
} |
|
1132 |
||
1133 |
if (renderRadii) |
|
1134 |
graphicsContext->restore(); |
|
1135 |
} |
|
1136 |
||
1137 |
void RenderBoxModelObject::paintBoxShadow(GraphicsContext* context, int tx, int ty, int w, int h, const RenderStyle* s, ShadowStyle shadowStyle, bool begin, bool end) |
|
1138 |
{ |
|
1139 |
// FIXME: Deal with border-image. Would be great to use border-image as a mask. |
|
1140 |
||
1141 |
if (context->paintingDisabled()) |
|
1142 |
return; |
|
1143 |
||
1144 |
IntRect rect(tx, ty, w, h); |
|
1145 |
IntSize topLeft; |
|
1146 |
IntSize topRight; |
|
1147 |
IntSize bottomLeft; |
|
1148 |
IntSize bottomRight; |
|
1149 |
||
1150 |
bool hasBorderRadius = s->hasBorderRadius(); |
|
1151 |
if (hasBorderRadius && (begin || end)) { |
|
1152 |
IntSize topLeftRadius, topRightRadius, bottomLeftRadius, bottomRightRadius; |
|
1153 |
s->getBorderRadiiForRect(rect, topLeftRadius, topRightRadius, bottomLeftRadius, bottomRightRadius); |
|
1154 |
||
1155 |
if (begin) { |
|
1156 |
if (shadowStyle == Inset) { |
|
1157 |
topLeftRadius.expand(-borderLeft(), -borderTop()); |
|
1158 |
topLeftRadius.clampNegativeToZero(); |
|
1159 |
bottomLeftRadius.expand(-borderLeft(), -borderBottom()); |
|
1160 |
bottomLeftRadius.clampNegativeToZero(); |
|
1161 |
} |
|
1162 |
topLeft = topLeftRadius; |
|
1163 |
bottomLeft = bottomLeftRadius; |
|
1164 |
} |
|
1165 |
if (end) { |
|
1166 |
if (shadowStyle == Inset) { |
|
1167 |
topRightRadius.expand(-borderRight(), -borderTop()); |
|
1168 |
topRightRadius.clampNegativeToZero(); |
|
1169 |
bottomRightRadius.expand(-borderRight(), -borderBottom()); |
|
1170 |
bottomRightRadius.clampNegativeToZero(); |
|
1171 |
} |
|
1172 |
topRight = topRightRadius; |
|
1173 |
bottomRight = bottomRightRadius; |
|
1174 |
} |
|
1175 |
} |
|
1176 |
||
1177 |
if (shadowStyle == Inset) { |
|
1178 |
rect.move(begin ? borderLeft() : 0, borderTop()); |
|
1179 |
rect.setWidth(rect.width() - (begin ? borderLeft() : 0) - (end ? borderRight() : 0)); |
|
1180 |
rect.setHeight(rect.height() - borderTop() - borderBottom()); |
|
1181 |
} |
|
1182 |
||
1183 |
bool hasOpaqueBackground = s->backgroundColor().isValid() && s->backgroundColor().alpha() == 255; |
|
1184 |
for (ShadowData* shadow = s->boxShadow(); shadow; shadow = shadow->next) { |
|
1185 |
if (shadow->style != shadowStyle) |
|
1186 |
continue; |
|
1187 |
||
1188 |
IntSize shadowOffset(shadow->x, shadow->y); |
|
1189 |
int shadowBlur = shadow->blur; |
|
1190 |
int shadowSpread = shadow->spread; |
|
1191 |
Color& shadowColor = shadow->color; |
|
1192 |
||
1193 |
if (shadow->style == Normal) { |
|
1194 |
IntRect fillRect(rect); |
|
1195 |
fillRect.inflate(shadowSpread); |
|
1196 |
if (fillRect.isEmpty()) |
|
1197 |
continue; |
|
1198 |
||
1199 |
IntRect shadowRect(rect); |
|
1200 |
shadowRect.inflate(shadowBlur + shadowSpread); |
|
1201 |
shadowRect.move(shadowOffset); |
|
1202 |
||
1203 |
context->save(); |
|
1204 |
context->clip(shadowRect); |
|
1205 |
||
1206 |
// Move the fill just outside the clip, adding 1 pixel separation so that the fill does not |
|
1207 |
// bleed in (due to antialiasing) if the context is transformed. |
|
1208 |
IntSize extraOffset(w + max(0, shadowOffset.width()) + shadowBlur + 2 * shadowSpread + 1, 0); |
|
1209 |
shadowOffset -= extraOffset; |
|
1210 |
fillRect.move(extraOffset); |
|
1211 |
||
1212 |
context->setShadow(shadowOffset, shadowBlur, shadowColor); |
|
1213 |
if (hasBorderRadius) { |
|
1214 |
IntRect rectToClipOut = rect; |
|
1215 |
IntSize topLeftToClipOut = topLeft; |
|
1216 |
IntSize topRightToClipOut = topRight; |
|
1217 |
IntSize bottomLeftToClipOut = bottomLeft; |
|
1218 |
IntSize bottomRightToClipOut = bottomRight; |
|
1219 |
||
1220 |
if (shadowSpread < 0) { |
|
1221 |
topLeft.expand(shadowSpread, shadowSpread); |
|
1222 |
topLeft.clampNegativeToZero(); |
|
1223 |
||
1224 |
topRight.expand(shadowSpread, shadowSpread); |
|
1225 |
topRight.clampNegativeToZero(); |
|
1226 |
||
1227 |
bottomLeft.expand(shadowSpread, shadowSpread); |
|
1228 |
bottomLeft.clampNegativeToZero(); |
|
1229 |
||
1230 |
bottomRight.expand(shadowSpread, shadowSpread); |
|
1231 |
bottomRight.clampNegativeToZero(); |
|
1232 |
} |
|
1233 |
||
1234 |
// If the box is opaque, it is unnecessary to clip it out. However, doing so saves time |
|
1235 |
// when painting the shadow. On the other hand, it introduces subpixel gaps along the |
|
1236 |
// corners. Those are avoided by insetting the clipping path by one pixel. |
|
1237 |
if (hasOpaqueBackground) { |
|
1238 |
rectToClipOut.inflate(-1); |
|
1239 |
||
1240 |
topLeftToClipOut.expand(-1, -1); |
|
1241 |
topLeftToClipOut.clampNegativeToZero(); |
|
1242 |
||
1243 |
topRightToClipOut.expand(-1, -1); |
|
1244 |
topRightToClipOut.clampNegativeToZero(); |
|
1245 |
||
1246 |
bottomLeftToClipOut.expand(-1, -1); |
|
1247 |
bottomLeftToClipOut.clampNegativeToZero(); |
|
1248 |
||
1249 |
bottomRightToClipOut.expand(-1, -1); |
|
1250 |
bottomRightToClipOut.clampNegativeToZero(); |
|
1251 |
} |
|
1252 |
||
1253 |
if (!rectToClipOut.isEmpty()) |
|
1254 |
context->clipOutRoundedRect(rectToClipOut, topLeftToClipOut, topRightToClipOut, bottomLeftToClipOut, bottomRightToClipOut); |
|
1255 |
context->fillRoundedRect(fillRect, topLeft, topRight, bottomLeft, bottomRight, Color::black); |
|
1256 |
} else { |
|
1257 |
IntRect rectToClipOut = rect; |
|
1258 |
||
1259 |
// If the box is opaque, it is unnecessary to clip it out. However, doing so saves time |
|
1260 |
// when painting the shadow. On the other hand, it introduces subpixel gaps along the |
|
1261 |
// edges if they are not pixel-aligned. Those are avoided by insetting the clipping path |
|
1262 |
// by one pixel. |
|
1263 |
if (hasOpaqueBackground) { |
|
1264 |
TransformationMatrix currentTransformation = context->getCTM(); |
|
1265 |
if (currentTransformation.a() != 1 || (currentTransformation.d() != 1 && currentTransformation.d() != -1) |
|
1266 |
|| currentTransformation.b() || currentTransformation.c()) |
|
1267 |
rectToClipOut.inflate(-1); |
|
1268 |
} |
|
1269 |
||
1270 |
if (!rectToClipOut.isEmpty()) |
|
1271 |
context->clipOut(rectToClipOut); |
|
1272 |
context->fillRect(fillRect, Color::black); |
|
1273 |
} |
|
1274 |
||
1275 |
context->restore(); |
|
1276 |
} else { |
|
1277 |
// Inset shadow. |
|
1278 |
IntRect holeRect(rect); |
|
1279 |
holeRect.inflate(-shadowSpread); |
|
1280 |
||
1281 |
if (holeRect.isEmpty()) { |
|
1282 |
if (hasBorderRadius) |
|
1283 |
context->fillRoundedRect(rect, topLeft, topRight, bottomLeft, bottomRight, shadowColor); |
|
1284 |
else |
|
1285 |
context->fillRect(rect, shadowColor); |
|
1286 |
continue; |
|
1287 |
} |
|
1288 |
if (!begin) { |
|
1289 |
holeRect.move(-max(shadowOffset.width(), 0) - shadowBlur, 0); |
|
1290 |
holeRect.setWidth(holeRect.width() + max(shadowOffset.width(), 0) + shadowBlur); |
|
1291 |
} |
|
1292 |
if (!end) |
|
1293 |
holeRect.setWidth(holeRect.width() - min(shadowOffset.width(), 0) + shadowBlur); |
|
1294 |
||
1295 |
Color fillColor(shadowColor.red(), shadowColor.green(), shadowColor.blue(), 255); |
|
1296 |
||
1297 |
IntRect outerRect(rect); |
|
1298 |
outerRect.inflateX(w - 2 * shadowSpread); |
|
1299 |
outerRect.inflateY(h - 2 * shadowSpread); |
|
1300 |
||
1301 |
context->save(); |
|
1302 |
||
1303 |
if (hasBorderRadius) |
|
1304 |
context->clip(Path::createRoundedRectangle(rect, topLeft, topRight, bottomLeft, bottomRight)); |
|
1305 |
else |
|
1306 |
context->clip(rect); |
|
1307 |
||
1308 |
IntSize extraOffset(2 * w + max(0, shadowOffset.width()) + shadowBlur - 2 * shadowSpread + 1, 0); |
|
1309 |
context->translate(extraOffset.width(), extraOffset.height()); |
|
1310 |
shadowOffset -= extraOffset; |
|
1311 |
||
1312 |
context->beginPath(); |
|
1313 |
context->addPath(Path::createRectangle(outerRect)); |
|
1314 |
||
1315 |
if (hasBorderRadius) { |
|
1316 |
if (shadowSpread > 0) { |
|
1317 |
topLeft.expand(-shadowSpread, -shadowSpread); |
|
1318 |
topLeft.clampNegativeToZero(); |
|
1319 |
||
1320 |
topRight.expand(-shadowSpread, -shadowSpread); |
|
1321 |
topRight.clampNegativeToZero(); |
|
1322 |
||
1323 |
bottomLeft.expand(-shadowSpread, -shadowSpread); |
|
1324 |
bottomLeft.clampNegativeToZero(); |
|
1325 |
||
1326 |
bottomRight.expand(-shadowSpread, -shadowSpread); |
|
1327 |
bottomRight.clampNegativeToZero(); |
|
1328 |
} |
|
1329 |
context->addPath(Path::createRoundedRectangle(holeRect, topLeft, topRight, bottomLeft, bottomRight)); |
|
1330 |
} else |
|
1331 |
context->addPath(Path::createRectangle(holeRect)); |
|
1332 |
||
1333 |
context->setFillRule(RULE_EVENODD); |
|
1334 |
context->setFillColor(fillColor); |
|
1335 |
context->setShadow(shadowOffset, shadowBlur, shadowColor); |
|
1336 |
context->fillPath(); |
|
1337 |
||
1338 |
context->restore(); |
|
1339 |
} |
|
1340 |
} |
|
1341 |
} |
|
1342 |
||
1343 |
int RenderBoxModelObject::containingBlockWidthForContent() const |
|
1344 |
{ |
|
1345 |
return containingBlock()->availableWidth(); |
|
1346 |
} |
|
1347 |
||
1348 |
} // namespace WebCore |