| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2004, 2008, 2009, 2010 Apple Inc. All rights reserved. | 2 * Copyright (C) 2004, 2008, 2009, 2010 Apple Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 | 27 |
| 28 #include "core/editing/EditingUtilities.h" | 28 #include "core/editing/EditingUtilities.h" |
| 29 #include "core/editing/VisibleUnits.h" | 29 #include "core/editing/VisibleUnits.h" |
| 30 #include "core/frame/FrameView.h" | 30 #include "core/frame/FrameView.h" |
| 31 #include "core/frame/Settings.h" | 31 #include "core/frame/Settings.h" |
| 32 #include "core/layout/LayoutBlock.h" | 32 #include "core/layout/LayoutBlock.h" |
| 33 #include "core/layout/LayoutView.h" | 33 #include "core/layout/LayoutView.h" |
| 34 #include "core/layout/api/LayoutBlockItem.h" | 34 #include "core/layout/api/LayoutBlockItem.h" |
| 35 #include "core/layout/api/LayoutItem.h" | 35 #include "core/layout/api/LayoutItem.h" |
| 36 #include "core/paint/PaintInfo.h" | 36 #include "core/paint/PaintInfo.h" |
| 37 #include "core/paint/PaintLayer.h" | |
| 38 #include "platform/graphics/GraphicsContext.h" | 37 #include "platform/graphics/GraphicsContext.h" |
| 39 #include "platform/graphics/GraphicsLayer.h" | |
| 40 #include "platform/graphics/paint/DrawingRecorder.h" | |
| 41 | 38 |
| 42 namespace blink { | 39 namespace blink { |
| 43 | 40 |
| 44 CaretBase::CaretBase(CaretVisibility visibility) | 41 CaretBase::CaretBase(CaretVisibility visibility) |
| 45 : m_caretVisibility(visibility) | 42 : m_caretVisibility(visibility) |
| 46 { | 43 { |
| 47 } | 44 } |
| 48 | 45 |
| 49 CaretBase::~CaretBase() = default; | 46 CaretBase::~CaretBase() = default; |
| 50 | 47 |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 { | 132 { |
| 136 LayoutBlock* caretPainter = caretLayoutObject(node); | 133 LayoutBlock* caretPainter = caretLayoutObject(node); |
| 137 if (!caretPainter) | 134 if (!caretPainter) |
| 138 return IntRect(); | 135 return IntRect(); |
| 139 | 136 |
| 140 LayoutRect localRect(rect); | 137 LayoutRect localRect(rect); |
| 141 caretPainter->flipForWritingMode(localRect); | 138 caretPainter->flipForWritingMode(localRect); |
| 142 return caretPainter->localToAbsoluteQuad(FloatRect(localRect)).enclosingBoun
dingBox(); | 139 return caretPainter->localToAbsoluteQuad(FloatRect(localRect)).enclosingBoun
dingBox(); |
| 143 } | 140 } |
| 144 | 141 |
| 145 DisplayItemClient* CaretBase::displayItemClientForCaret(Node* node) | |
| 146 { | |
| 147 LayoutBlock* caretLayoutBlock = caretLayoutObject(node); | |
| 148 if (caretLayoutBlock->usesCompositedScrolling()) | |
| 149 return static_cast<DisplayItemClient*>(caretLayoutBlock->layer()->graphi
csLayerBackingForScrolling()); | |
| 150 return caretLayoutBlock; | |
| 151 } | |
| 152 | |
| 153 // TODO(yoichio): |node| is FrameSelection::m_previousCaretNode and this is bad | 142 // TODO(yoichio): |node| is FrameSelection::m_previousCaretNode and this is bad |
| 154 // design. We should use only previous layoutObject or Rectangle to invalidate | 143 // design. We should use only previous layoutObject or Rectangle to invalidate |
| 155 // old caret. | 144 // old caret. |
| 156 void CaretBase::invalidateLocalCaretRect(Node* node, const LayoutRect& rect) | 145 void CaretBase::invalidateLocalCaretRect(Node* node, const LayoutRect& rect) |
| 157 { | 146 { |
| 158 LayoutBlock* caretLayoutBlock = caretLayoutObject(node); | 147 LayoutBlockItem caretPainter = LayoutBlockItem(caretLayoutObject(node)); |
| 159 if (!caretLayoutBlock) | 148 if (!caretPainter) |
| 160 return; | 149 return; |
| 161 | 150 |
| 162 // FIXME: Need to over-paint 1 pixel to workaround some rounding problems. | 151 // FIXME: Need to over-paint 1 pixel to workaround some rounding problems. |
| 163 // https://bugs.webkit.org/show_bug.cgi?id=108283 | 152 // https://bugs.webkit.org/show_bug.cgi?id=108283 |
| 164 LayoutRect inflatedRect = rect; | 153 LayoutRect inflatedRect = rect; |
| 165 inflatedRect.inflate(LayoutUnit(1)); | 154 inflatedRect.inflate(LayoutUnit(1)); |
| 166 | 155 |
| 156 // FIXME: We should use mapLocalToAncestor() since we know we're not un-root
ed. |
| 157 mapCaretRectToCaretPainter(LayoutItem(node->layoutObject()), caretPainter, i
nflatedRect); |
| 158 |
| 167 // FIXME: We should not allow paint invalidation out of paint invalidation s
tate. crbug.com/457415 | 159 // FIXME: We should not allow paint invalidation out of paint invalidation s
tate. crbug.com/457415 |
| 168 DisablePaintInvalidationStateAsserts disabler; | 160 DisablePaintInvalidationStateAsserts disabler; |
| 169 | 161 caretPainter.invalidatePaintRectangle(inflatedRect); |
| 170 node->layoutObject()->invalidatePaintRectangle(inflatedRect, displayItemClie
ntForCaret(node)); | |
| 171 } | 162 } |
| 172 | 163 |
| 173 bool CaretBase::shouldRepaintCaret(Node& node) const | 164 bool CaretBase::shouldRepaintCaret(Node& node) const |
| 174 { | 165 { |
| 175 // If PositionAnchorType::BeforeAnchor or PositionAnchorType::AfterAnchor, | 166 // If PositionAnchorType::BeforeAnchor or PositionAnchorType::AfterAnchor, |
| 176 // carets need to be repainted not only when the node is contentEditable but | 167 // carets need to be repainted not only when the node is contentEditable but |
| 177 // also when its parentNode() is contentEditable. | 168 // also when its parentNode() is contentEditable. |
| 178 node.document().updateStyleAndLayoutTree(); | 169 node.document().updateStyleAndLayoutTree(); |
| 179 return hasEditableStyle(node) || (node.parentNode() && hasEditableStyle(*nod
e.parentNode())); | 170 return hasEditableStyle(node) || (node.parentNode() && hasEditableStyle(*nod
e.parentNode())); |
| 180 } | 171 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 194 if (caretRectChanged) | 185 if (caretRectChanged) |
| 195 return; | 186 return; |
| 196 | 187 |
| 197 if (LayoutViewItem view = node->document().layoutViewItem()) { | 188 if (LayoutViewItem view = node->document().layoutViewItem()) { |
| 198 node->document().updateStyleAndLayoutTree(); | 189 node->document().updateStyleAndLayoutTree(); |
| 199 if (hasEditableStyle(*node) || shouldRepaintCaret(view)) | 190 if (hasEditableStyle(*node) || shouldRepaintCaret(view)) |
| 200 invalidateLocalCaretRect(node, localCaretRectWithoutUpdate()); | 191 invalidateLocalCaretRect(node, localCaretRectWithoutUpdate()); |
| 201 } | 192 } |
| 202 } | 193 } |
| 203 | 194 |
| 204 void CaretBase::paintCaret(Node* node, GraphicsContext& context, const LayoutPoi
nt& paintOffset, DisplayItem::Type displayItemType) const | 195 void CaretBase::paintCaret(Node* node, GraphicsContext& context, const LayoutPoi
nt& paintOffset) const |
| 205 { | 196 { |
| 206 if (m_caretVisibility == CaretVisibility::Hidden) | 197 if (m_caretVisibility == CaretVisibility::Hidden) |
| 207 return; | 198 return; |
| 208 | 199 |
| 209 if (DrawingRecorder::useCachedDrawingIfPossible(context, *displayItemClientF
orCaret(node), displayItemType)) | |
| 210 return; | |
| 211 | |
| 212 LayoutRect drawingRect = localCaretRectWithoutUpdate(); | 200 LayoutRect drawingRect = localCaretRectWithoutUpdate(); |
| 213 if (LayoutBlock* layoutObject = caretLayoutObject(node)) | 201 if (LayoutBlock* layoutObject = caretLayoutObject(node)) |
| 214 layoutObject->flipForWritingMode(drawingRect); | 202 layoutObject->flipForWritingMode(drawingRect); |
| 215 drawingRect.moveBy(roundedIntPoint(paintOffset)); | 203 drawingRect.moveBy(roundedIntPoint(paintOffset)); |
| 216 | 204 |
| 217 Color caretColor = Color::black; | 205 Color caretColor = Color::black; |
| 218 | 206 |
| 219 Element* element; | 207 Element* element; |
| 220 if (node->isElementNode()) | 208 if (node->isElementNode()) |
| 221 element = toElement(node); | 209 element = toElement(node); |
| 222 else | 210 else |
| 223 element = node->parentElement(); | 211 element = node->parentElement(); |
| 224 | 212 |
| 225 if (element && element->layoutObject()) | 213 if (element && element->layoutObject()) |
| 226 caretColor = element->layoutObject()->resolveColor(CSSPropertyColor); | 214 caretColor = element->layoutObject()->resolveColor(CSSPropertyColor); |
| 227 | 215 |
| 228 DrawingRecorder drawingRecorder(context, *displayItemClientForCaret(node), D
isplayItem::Caret, FloatRect(drawingRect)); | |
| 229 | |
| 230 context.fillRect(FloatRect(drawingRect), caretColor); | 216 context.fillRect(FloatRect(drawingRect), caretColor); |
| 231 } | 217 } |
| 232 | 218 |
| 233 void CaretBase::setCaretVisibility(CaretVisibility visibility) | 219 void CaretBase::setCaretVisibility(CaretVisibility visibility) |
| 234 { | 220 { |
| 235 m_caretVisibility = visibility; | 221 m_caretVisibility = visibility; |
| 236 } | 222 } |
| 237 | 223 |
| 238 } // namespace blink | 224 } // namespace blink |
| OLD | NEW |