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

Side by Side Diff: third_party/WebKit/Source/core/editing/RenderedPosition.cpp

Issue 2620383004: Fix graphics layer backing and offset for composited selection handles. (Closed)
Patch Set: none Created 3 years, 11 months 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 /* 1 /*
2 * Copyright (C) 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2011 Google 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 are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 return IntRect(); 258 return IntRect();
259 259
260 IntRect localRect = pixelSnappedIntRect(m_layoutObject->localCaretRect( 260 IntRect localRect = pixelSnappedIntRect(m_layoutObject->localCaretRect(
261 m_inlineBox, m_offset, extraWidthToEndOfLine)); 261 m_inlineBox, m_offset, extraWidthToEndOfLine));
262 return localRect == IntRect() 262 return localRect == IntRect()
263 ? IntRect() 263 ? IntRect()
264 : m_layoutObject->localToAbsoluteQuad(FloatRect(localRect)) 264 : m_layoutObject->localToAbsoluteQuad(FloatRect(localRect))
265 .enclosingBoundingBox(); 265 .enclosingBoundingBox();
266 } 266 }
267 267
268 // Convert a local point into the coordinate system of backing coordinates.
269 // Also returns the backing layer if needed.
270 FloatPoint RenderedPosition::localToInvalidationBackingPoint(
271 const LayoutPoint& localPoint,
272 GraphicsLayer** graphicsLayerBacking) const {
273 const LayoutBoxModelObject& paintInvalidationContainer =
274 m_layoutObject->containerForPaintInvalidation();
275 DCHECK(paintInvalidationContainer.layer());
276
277 FloatPoint containerPoint = m_layoutObject->localToAncestorPoint(
278 FloatPoint(localPoint), &paintInvalidationContainer,
279 TraverseDocumentBoundaries);
280
281 // A layoutObject can have no invalidation backing if it is from a detached
282 // frame, or when forced compositing is disabled.
283 if (paintInvalidationContainer.layer()->compositingState() == NotComposited)
284 return containerPoint;
285
286 PaintLayer::mapPointInPaintInvalidationContainerToBacking(
287 paintInvalidationContainer, containerPoint);
288
289 // Must not use the scrolling contents layer, so pass
290 // |paintInvalidationContainer|.
291 if (GraphicsLayer* graphicsLayer =
292 paintInvalidationContainer.layer()->graphicsLayerBacking(
293 &paintInvalidationContainer)) {
294 if (graphicsLayerBacking)
295 *graphicsLayerBacking = graphicsLayer;
296
297 containerPoint.move(-graphicsLayer->offsetFromLayoutObject());
298 }
299
300 return containerPoint;
301 }
302
268 void RenderedPosition::positionInGraphicsLayerBacking( 303 void RenderedPosition::positionInGraphicsLayerBacking(
269 CompositedSelectionBound& bound, 304 CompositedSelectionBound& bound,
270 bool selectionStart) const { 305 bool selectionStart) const {
271 bound.layer = nullptr; 306 bound.layer = nullptr;
272 bound.edgeTopInLayer = bound.edgeBottomInLayer = FloatPoint(); 307 bound.edgeTopInLayer = bound.edgeBottomInLayer = FloatPoint();
273 308
274 if (isNull()) 309 if (isNull())
275 return; 310 return;
276 311
277 LayoutRect rect = m_layoutObject->localCaretRect(m_inlineBox, m_offset); 312 LayoutRect rect = m_layoutObject->localCaretRect(m_inlineBox, m_offset);
278 PaintLayer* layer = nullptr;
279 if (m_layoutObject->style()->isHorizontalWritingMode()) { 313 if (m_layoutObject->style()->isHorizontalWritingMode()) {
280 bound.edgeTopInLayer = m_layoutObject->localToInvalidationBackingPoint( 314 bound.edgeTopInLayer =
281 rect.minXMinYCorner(), &layer); 315 localToInvalidationBackingPoint(rect.minXMinYCorner(), &bound.layer);
282 bound.edgeBottomInLayer = m_layoutObject->localToInvalidationBackingPoint( 316 bound.edgeBottomInLayer =
283 rect.minXMaxYCorner(), nullptr); 317 localToInvalidationBackingPoint(rect.minXMaxYCorner(), nullptr);
284 } else { 318 } else {
285 bound.edgeTopInLayer = m_layoutObject->localToInvalidationBackingPoint( 319 bound.edgeTopInLayer =
286 rect.minXMinYCorner(), &layer); 320 localToInvalidationBackingPoint(rect.minXMinYCorner(), &bound.layer);
287 bound.edgeBottomInLayer = m_layoutObject->localToInvalidationBackingPoint( 321 bound.edgeBottomInLayer =
288 rect.maxXMinYCorner(), nullptr); 322 localToInvalidationBackingPoint(rect.maxXMinYCorner(), nullptr);
289 323
290 // When text is vertical, it looks better for the start handle baseline to 324 // When text is vertical, it looks better for the start handle baseline to
291 // be at the starting edge, to enclose the selection fully between the 325 // be at the starting edge, to enclose the selection fully between the
292 // handles. 326 // handles.
293 if (selectionStart) { 327 if (selectionStart) {
294 float xSwap = bound.edgeBottomInLayer.x(); 328 float xSwap = bound.edgeBottomInLayer.x();
295 bound.edgeBottomInLayer.setX(bound.edgeTopInLayer.x()); 329 bound.edgeBottomInLayer.setX(bound.edgeTopInLayer.x());
296 bound.edgeTopInLayer.setX(xSwap); 330 bound.edgeTopInLayer.setX(xSwap);
297 } 331 }
298 332
299 // Flipped blocks writing mode is not only vertical but also right to left. 333 // Flipped blocks writing mode is not only vertical but also right to left.
300 bound.isTextDirectionRTL = m_layoutObject->hasFlippedBlocksWritingMode(); 334 bound.isTextDirectionRTL = m_layoutObject->hasFlippedBlocksWritingMode();
301 } 335 }
302
303 bound.layer = layer ? layer->graphicsLayerBacking() : nullptr;
304 } 336 }
305 337
306 bool layoutObjectContainsPosition(LayoutObject* target, 338 bool layoutObjectContainsPosition(LayoutObject* target,
307 const Position& position) { 339 const Position& position) {
308 for (LayoutObject* layoutObject = layoutObjectFromPosition(position); 340 for (LayoutObject* layoutObject = layoutObjectFromPosition(position);
309 layoutObject && layoutObject->node(); 341 layoutObject && layoutObject->node();
310 layoutObject = layoutObject->parent()) { 342 layoutObject = layoutObject->parent()) {
311 if (layoutObject == target) 343 if (layoutObject == target)
312 return true; 344 return true;
313 } 345 }
314 return false; 346 return false;
315 } 347 }
316 348
317 } // namespace blink 349 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/editing/RenderedPosition.h ('k') | third_party/WebKit/Source/core/layout/LayoutObject.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698