Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(99)

Side by Side Diff: third_party/WebKit/Source/core/paint/BoxClipper.cpp

Issue 1448253002: Clip scrollbars to box bounds when they don't fit. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "config.h" 5 #include "config.h"
6 #include "core/paint/BoxClipper.h" 6 #include "core/paint/BoxClipper.h"
7 7
8 #include "core/layout/LayoutBox.h" 8 #include "core/layout/LayoutBox.h"
9 #include "core/paint/PaintInfo.h" 9 #include "core/paint/PaintInfo.h"
10 #include "core/paint/PaintLayer.h" 10 #include "core/paint/PaintLayer.h"
11 #include "platform/RuntimeEnabledFeatures.h" 11 #include "platform/RuntimeEnabledFeatures.h"
12 #include "platform/graphics/GraphicsLayer.h" 12 #include "platform/graphics/GraphicsLayer.h"
13 #include "platform/graphics/paint/ClipDisplayItem.h" 13 #include "platform/graphics/paint/ClipDisplayItem.h"
14 #include "platform/graphics/paint/PaintController.h" 14 #include "platform/graphics/paint/PaintController.h"
15 15
16 namespace blink { 16 namespace blink {
17 17
18 BoxClipper::BoxClipper(const LayoutBox& box, const PaintInfo& paintInfo, const L ayoutPoint& accumulatedOffset, ContentsClipBehavior contentsClipBehavior) 18 BoxClipper::BoxClipper(const LayoutBox& box, const PaintInfo& paintInfo, const L ayoutPoint& accumulatedOffset, ContentsClipBehavior contentsClipBehavior)
19 : m_box(box) 19 : m_box(box)
20 , m_paintInfo(paintInfo) 20 , m_paintInfo(paintInfo)
21 , m_clipType(DisplayItem::UninitializedType) 21 , m_clipType(DisplayItem::UninitializedType)
22 { 22 {
23 if (m_paintInfo.phase == PaintPhaseBlockBackground || m_paintInfo.phase == P aintPhaseSelfOutline || m_paintInfo.phase == PaintPhaseMask) 23 if ((m_paintInfo.phase == PaintPhaseBlockBackground && contentsClipBehavior != ClipForScrollbars)
24 || m_paintInfo.phase == PaintPhaseSelfOutline || m_paintInfo.phase == Pa intPhaseMask)
24 return; 25 return;
25 26
26 bool isControlClip = m_box.hasControlClip(); 27 bool hasControlClip = m_box.hasControlClip();
27 bool isOverflowClip = m_box.hasOverflowClip() && !m_box.layer()->isSelfPaint ingLayer(); 28 bool hasOverflowClip = m_box.hasOverflowClip() && !m_box.layer()->isSelfPain tingLayer();
28 29
29 if (!isControlClip && !isOverflowClip) 30 if (!hasControlClip && !hasOverflowClip)
30 return; 31 return;
31 32
32 LayoutRect clipRect = isControlClip ? m_box.controlClipRect(accumulatedOffse t) : m_box.overflowClipRect(accumulatedOffset); 33 LayoutRect clipRect;
34
35 if (hasControlClip) {
36 clipRect = m_box.controlClipRect(accumulatedOffset);
37 } else {
38 ASSERT(hasOverflowClip);
39 if (contentsClipBehavior == ClipForScrollbars) {
40 clipRect = m_box.borderBoxRect();
41 clipRect.moveBy(accumulatedOffset);
42 } else {
43 clipRect = m_box.overflowClipRect(accumulatedOffset);
44 }
45 }
46
33 FloatRoundedRect clipRoundedRect(0, 0, 0, 0); 47 FloatRoundedRect clipRoundedRect(0, 0, 0, 0);
34 bool hasBorderRadius = m_box.style()->hasBorderRadius(); 48 // Scrollbars paint on top of a rounded border.
35 if (hasBorderRadius) 49 bool shouldClipBorderRadius = m_box.style()->hasBorderRadius() && contentsCl ipBehavior != ClipForScrollbars;
50 if (shouldClipBorderRadius)
36 clipRoundedRect = m_box.style()->getRoundedInnerBorderFor(LayoutRect(acc umulatedOffset, m_box.size())); 51 clipRoundedRect = m_box.style()->getRoundedInnerBorderFor(LayoutRect(acc umulatedOffset, m_box.size()));
37 52
38 if (contentsClipBehavior == SkipContentsClipIfPossible) { 53 if (contentsClipBehavior == SkipContentsClipIfPossible) {
39 LayoutRect contentsVisualOverflow = m_box.contentsVisualOverflowRect(); 54 LayoutRect contentsVisualOverflow = m_box.contentsVisualOverflowRect();
40 if (contentsVisualOverflow.isEmpty()) 55 if (contentsVisualOverflow.isEmpty())
41 return; 56 return;
42 57
43 LayoutRect conservativeClipRect = clipRect; 58 LayoutRect conservativeClipRect = clipRect;
44 if (hasBorderRadius) 59 if (shouldClipBorderRadius)
45 conservativeClipRect.intersect(LayoutRect(clipRoundedRect.radiusCent erRect())); 60 conservativeClipRect.intersect(LayoutRect(clipRoundedRect.radiusCent erRect()));
46 conservativeClipRect.moveBy(-accumulatedOffset); 61 conservativeClipRect.moveBy(-accumulatedOffset);
47 if (m_box.hasLayer()) 62 if (m_box.hasLayer())
48 conservativeClipRect.move(m_box.scrolledContentOffset()); 63 conservativeClipRect.move(m_box.scrolledContentOffset());
49 if (conservativeClipRect.contains(contentsVisualOverflow)) 64 if (conservativeClipRect.contains(contentsVisualOverflow))
50 return; 65 return;
51 } 66 }
52 67
53 if (!m_paintInfo.context->paintController().displayItemConstructionIsDisable d()) { 68 if (!m_paintInfo.context->paintController().displayItemConstructionIsDisable d()) {
54 m_clipType = m_paintInfo.displayItemTypeForClipping(); 69 m_clipType = m_paintInfo.displayItemTypeForClipping();
55 Vector<FloatRoundedRect> roundedRects; 70 Vector<FloatRoundedRect> roundedRects;
56 if (hasBorderRadius) 71 if (shouldClipBorderRadius)
57 roundedRects.append(clipRoundedRect); 72 roundedRects.append(clipRoundedRect);
58 m_paintInfo.context->paintController().createAndAppend<ClipDisplayItem>( m_box, m_clipType, pixelSnappedIntRect(clipRect), roundedRects); 73 m_paintInfo.context->paintController().createAndAppend<ClipDisplayItem>( m_box, m_clipType, pixelSnappedIntRect(clipRect), roundedRects);
59 } 74 }
60 } 75 }
61 76
62 BoxClipper::~BoxClipper() 77 BoxClipper::~BoxClipper()
63 { 78 {
64 if (m_clipType == DisplayItem::UninitializedType) 79 if (m_clipType == DisplayItem::UninitializedType)
65 return; 80 return;
66 81
67 ASSERT(m_box.hasControlClip() || (m_box.hasOverflowClip() && !m_box.layer()- >isSelfPaintingLayer())); 82 ASSERT(m_box.hasControlClip() || (m_box.hasOverflowClip() && !m_box.layer()- >isSelfPaintingLayer()));
68 m_paintInfo.context->paintController().endItem<EndClipDisplayItem>(m_box, Di splayItem::clipTypeToEndClipType(m_clipType)); 83 m_paintInfo.context->paintController().endItem<EndClipDisplayItem>(m_box, Di splayItem::clipTypeToEndClipType(m_clipType));
69 } 84 }
70 85
71 } // namespace blink 86 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698