| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "core/paint/ObjectPainter.h" | 5 #include "core/paint/ObjectPainter.h" |
| 6 | 6 |
| 7 #include "core/layout/LayoutBlock.h" | 7 #include "core/layout/LayoutBlock.h" |
| 8 #include "core/layout/LayoutInline.h" | 8 #include "core/layout/LayoutInline.h" |
| 9 #include "core/layout/LayoutObject.h" | 9 #include "core/layout/LayoutObject.h" |
| 10 #include "core/layout/LayoutTheme.h" | 10 #include "core/layout/LayoutTheme.h" |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 int x2; | 41 int x2; |
| 42 int y2; | 42 int y2; |
| 43 BoxSide side; | 43 BoxSide side; |
| 44 }; | 44 }; |
| 45 | 45 |
| 46 // Adjust length of edges if needed. Returns the width of the joint. | 46 // Adjust length of edges if needed. Returns the width of the joint. |
| 47 int adjustJoint(int outlineWidth, | 47 int adjustJoint(int outlineWidth, |
| 48 OutlineEdgeInfo& edge1, | 48 OutlineEdgeInfo& edge1, |
| 49 OutlineEdgeInfo& edge2) { | 49 OutlineEdgeInfo& edge2) { |
| 50 // A clockwise joint: | 50 // A clockwise joint: |
| 51 // - needs no adjustment of edge length because our edges are along the clockw
ise outer edge of the outline; | 51 // - needs no adjustment of edge length because our edges are along the |
| 52 // clockwise outer edge of the outline; |
| 52 // - needs a positive adjacent joint width (required by drawLineForBoxSide). | 53 // - needs a positive adjacent joint width (required by drawLineForBoxSide). |
| 53 // A counterclockwise joint: | 54 // A counterclockwise joint: |
| 54 // - needs to increase the edge length to include the joint; | 55 // - needs to increase the edge length to include the joint; |
| 55 // - needs a negative adjacent joint width (required by drawLineForBoxSide). | 56 // - needs a negative adjacent joint width (required by drawLineForBoxSide). |
| 56 switch (edge1.side) { | 57 switch (edge1.side) { |
| 57 case BSTop: | 58 case BSTop: |
| 58 switch (edge2.side) { | 59 switch (edge2.side) { |
| 59 case BSRight: // Clockwise | 60 case BSRight: // Clockwise |
| 60 return outlineWidth; | 61 return outlineWidth; |
| 61 case BSLeft: // Counterclockwise | 62 case BSLeft: // Counterclockwise |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 bool useTransparencyLayer = color.hasAlpha(); | 169 bool useTransparencyLayer = color.hasAlpha(); |
| 169 if (useTransparencyLayer) { | 170 if (useTransparencyLayer) { |
| 170 graphicsContext.beginLayer(static_cast<float>(color.alpha()) / 255); | 171 graphicsContext.beginLayer(static_cast<float>(color.alpha()) / 255); |
| 171 outlineColor = | 172 outlineColor = |
| 172 Color(outlineColor.red(), outlineColor.green(), outlineColor.blue()); | 173 Color(outlineColor.red(), outlineColor.green(), outlineColor.blue()); |
| 173 } | 174 } |
| 174 | 175 |
| 175 ASSERT(count >= 4 && edges.size() == count); | 176 ASSERT(count >= 4 && edges.size() == count); |
| 176 int firstAdjacentWidth = adjustJoint(width, edges.last(), edges.first()); | 177 int firstAdjacentWidth = adjustJoint(width, edges.last(), edges.first()); |
| 177 | 178 |
| 178 // The width of the angled part of starting and ending joint of the current ed
ge. | 179 // The width of the angled part of starting and ending joint of the current |
| 180 // edge. |
| 179 int adjacentWidthStart = firstAdjacentWidth; | 181 int adjacentWidthStart = firstAdjacentWidth; |
| 180 int adjacentWidthEnd; | 182 int adjacentWidthEnd; |
| 181 for (size_t i = 0; i < count; ++i) { | 183 for (size_t i = 0; i < count; ++i) { |
| 182 OutlineEdgeInfo& edge = edges[i]; | 184 OutlineEdgeInfo& edge = edges[i]; |
| 183 adjacentWidthEnd = i == count - 1 ? firstAdjacentWidth | 185 adjacentWidthEnd = i == count - 1 ? firstAdjacentWidth |
| 184 : adjustJoint(width, edge, edges[i + 1]); | 186 : adjustJoint(width, edge, edges[i + 1]); |
| 185 int adjacentWidth1 = adjacentWidthStart; | 187 int adjacentWidth1 = adjacentWidthStart; |
| 186 int adjacentWidth2 = adjacentWidthEnd; | 188 int adjacentWidth2 = adjacentWidthEnd; |
| 187 if (edge.side == BSLeft || edge.side == BSBottom) | 189 if (edge.side == BSLeft || edge.side == BSBottom) |
| 188 std::swap(adjacentWidth1, adjacentWidth2); | 190 std::swap(adjacentWidth1, adjacentWidth2); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 217 | 219 |
| 218 void ObjectPainter::paintOutline(const PaintInfo& paintInfo, | 220 void ObjectPainter::paintOutline(const PaintInfo& paintInfo, |
| 219 const LayoutPoint& paintOffset) { | 221 const LayoutPoint& paintOffset) { |
| 220 ASSERT(shouldPaintSelfOutline(paintInfo.phase)); | 222 ASSERT(shouldPaintSelfOutline(paintInfo.phase)); |
| 221 | 223 |
| 222 const ComputedStyle& styleToUse = m_layoutObject.styleRef(); | 224 const ComputedStyle& styleToUse = m_layoutObject.styleRef(); |
| 223 if (!styleToUse.hasOutline() || | 225 if (!styleToUse.hasOutline() || |
| 224 styleToUse.visibility() != EVisibility::Visible) | 226 styleToUse.visibility() != EVisibility::Visible) |
| 225 return; | 227 return; |
| 226 | 228 |
| 227 // Only paint the focus ring by hand if the theme isn't able to draw the focus
ring. | 229 // Only paint the focus ring by hand if the theme isn't able to draw the focus |
| 230 // ring. |
| 228 if (styleToUse.outlineStyleIsAuto() && | 231 if (styleToUse.outlineStyleIsAuto() && |
| 229 !LayoutTheme::theme().shouldDrawDefaultFocusRing(m_layoutObject)) | 232 !LayoutTheme::theme().shouldDrawDefaultFocusRing(m_layoutObject)) |
| 230 return; | 233 return; |
| 231 | 234 |
| 232 Vector<LayoutRect> outlineRects; | 235 Vector<LayoutRect> outlineRects; |
| 233 m_layoutObject.addOutlineRects( | 236 m_layoutObject.addOutlineRects( |
| 234 outlineRects, paintOffset, | 237 outlineRects, paintOffset, |
| 235 m_layoutObject.outlineRectsShouldIncludeBlockVisualOverflow()); | 238 m_layoutObject.outlineRectsShouldIncludeBlockVisualOverflow()); |
| 236 if (outlineRects.isEmpty()) | 239 if (outlineRects.isEmpty()) |
| 237 return; | 240 return; |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 int thickness; | 350 int thickness; |
| 348 int length; | 351 int length; |
| 349 if (side == BSTop || side == BSBottom) { | 352 if (side == BSTop || side == BSBottom) { |
| 350 thickness = y2 - y1; | 353 thickness = y2 - y1; |
| 351 length = x2 - x1; | 354 length = x2 - x1; |
| 352 } else { | 355 } else { |
| 353 thickness = x2 - x1; | 356 thickness = x2 - x1; |
| 354 length = y2 - y1; | 357 length = y2 - y1; |
| 355 } | 358 } |
| 356 | 359 |
| 357 // We would like this check to be an ASSERT as we don't want to draw empty bor
ders. However | 360 // We would like this check to be an ASSERT as we don't want to draw empty |
| 358 // nothing guarantees that the following recursive calls to drawLineForBoxSide
will have | 361 // borders. However nothing guarantees that the following recursive calls to |
| 359 // positive thickness and length. | 362 // drawLineForBoxSide will have positive thickness and length. |
| 360 if (length <= 0 || thickness <= 0) | 363 if (length <= 0 || thickness <= 0) |
| 361 return; | 364 return; |
| 362 | 365 |
| 363 if (style == BorderStyleDouble && thickness < 3) | 366 if (style == BorderStyleDouble && thickness < 3) |
| 364 style = BorderStyleSolid; | 367 style = BorderStyleSolid; |
| 365 | 368 |
| 366 switch (style) { | 369 switch (style) { |
| 367 case BorderStyleNone: | 370 case BorderStyleNone: |
| 368 case BorderStyleHidden: | 371 case BorderStyleHidden: |
| 369 return; | 372 return; |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 660 quad[2] = FloatPoint(x2, y2 - std::max(-adjacentWidth2, 0)); | 663 quad[2] = FloatPoint(x2, y2 - std::max(-adjacentWidth2, 0)); |
| 661 quad[3] = FloatPoint(x2, y1 + std::max(-adjacentWidth1, 0)); | 664 quad[3] = FloatPoint(x2, y1 + std::max(-adjacentWidth1, 0)); |
| 662 break; | 665 break; |
| 663 } | 666 } |
| 664 | 667 |
| 665 fillQuad(graphicsContext, quad, color, antialias); | 668 fillQuad(graphicsContext, quad, color, antialias); |
| 666 } | 669 } |
| 667 | 670 |
| 668 void ObjectPainter::paintAllPhasesAtomically(const PaintInfo& paintInfo, | 671 void ObjectPainter::paintAllPhasesAtomically(const PaintInfo& paintInfo, |
| 669 const LayoutPoint& paintOffset) { | 672 const LayoutPoint& paintOffset) { |
| 670 // Pass PaintPhaseSelection and PaintPhaseTextClip to the descendants so that
they will paint | 673 // Pass PaintPhaseSelection and PaintPhaseTextClip to the descendants so that |
| 671 // for selection and text clip respectively. We don't need complete painting f
or these phases. | 674 // they will paint for selection and text clip respectively. We don't need |
| 675 // complete painting for these phases. |
| 672 if (paintInfo.phase == PaintPhaseSelection || | 676 if (paintInfo.phase == PaintPhaseSelection || |
| 673 paintInfo.phase == PaintPhaseTextClip) { | 677 paintInfo.phase == PaintPhaseTextClip) { |
| 674 m_layoutObject.paint(paintInfo, paintOffset); | 678 m_layoutObject.paint(paintInfo, paintOffset); |
| 675 return; | 679 return; |
| 676 } | 680 } |
| 677 | 681 |
| 678 if (paintInfo.phase != PaintPhaseForeground) | 682 if (paintInfo.phase != PaintPhaseForeground) |
| 679 return; | 683 return; |
| 680 | 684 |
| 681 PaintInfo info(paintInfo); | 685 PaintInfo info(paintInfo); |
| 682 info.phase = PaintPhaseBlockBackground; | 686 info.phase = PaintPhaseBlockBackground; |
| 683 m_layoutObject.paint(info, paintOffset); | 687 m_layoutObject.paint(info, paintOffset); |
| 684 info.phase = PaintPhaseFloat; | 688 info.phase = PaintPhaseFloat; |
| 685 m_layoutObject.paint(info, paintOffset); | 689 m_layoutObject.paint(info, paintOffset); |
| 686 info.phase = PaintPhaseForeground; | 690 info.phase = PaintPhaseForeground; |
| 687 m_layoutObject.paint(info, paintOffset); | 691 m_layoutObject.paint(info, paintOffset); |
| 688 info.phase = PaintPhaseOutline; | 692 info.phase = PaintPhaseOutline; |
| 689 m_layoutObject.paint(info, paintOffset); | 693 m_layoutObject.paint(info, paintOffset); |
| 690 } | 694 } |
| 691 | 695 |
| 692 } // namespace blink | 696 } // namespace blink |
| OLD | NEW |