OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/BoxPaintInvalidator.h" | 5 #include "core/paint/BoxPaintInvalidator.h" |
6 | 6 |
7 #include "core/frame/Settings.h" | 7 #include "core/frame/Settings.h" |
8 #include "core/layout/LayoutView.h" | 8 #include "core/layout/LayoutView.h" |
9 #include "core/layout/compositing/CompositedLayerMapping.h" | 9 #include "core/layout/compositing/CompositedLayerMapping.h" |
10 #include "core/paint/ObjectPaintInvalidator.h" | 10 #include "core/paint/ObjectPaintInvalidator.h" |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
305 area->invalidatePaintOfScrollControlsIfNeeded(m_context); | 305 area->invalidatePaintOfScrollControlsIfNeeded(m_context); |
306 | 306 |
307 // This is for the next invalidatePaintIfNeeded so must be at the end. | 307 // This is for the next invalidatePaintIfNeeded so must be at the end. |
308 savePreviousBoxGeometriesIfNeeded(); | 308 savePreviousBoxGeometriesIfNeeded(); |
309 | 309 |
310 return reason; | 310 return reason; |
311 } | 311 } |
312 | 312 |
313 bool BoxPaintInvalidator::needsToSavePreviousBoxGeometries() { | 313 bool BoxPaintInvalidator::needsToSavePreviousBoxGeometries() { |
314 LayoutSize paintInvalidationSize = m_context.newVisualRect.size(); | 314 LayoutSize paintInvalidationSize = m_context.newVisualRect.size(); |
315 // Don't save old box Geometries if the paint rect is empty because we'll | |
316 // full invalidate once the paint rect becomes non-empty. | |
317 if (paintInvalidationSize.isEmpty()) | |
318 return false; | |
319 | 315 |
320 if (m_box.paintedOutputOfObjectHasNoEffectRegardlessOfSize()) | 316 // The shortcuts doesn't apply to HTML element. ViewPaintInvalidator needs to |
321 return false; | 317 // know its previous border box size even if it has visibility:hidden (causing |
318 // empty paintInvalidationSize) or has no painted output. | |
319 if (!m_box.node() || !m_box.node()->isHTMLElement()) { | |
320 // Don't save old box geometries if the paint rect is empty because we'll | |
321 // fully invalidate once the paint rect becomes non-empty. | |
322 if (paintInvalidationSize.isEmpty()) | |
323 return false; | |
324 | |
325 if (m_box.paintedOutputOfObjectHasNoEffectRegardlessOfSize()) | |
326 return false; | |
327 } | |
322 | 328 |
323 const ComputedStyle& style = m_box.styleRef(); | 329 const ComputedStyle& style = m_box.styleRef(); |
324 | 330 |
325 // If we use border-box sizing we need to track changes in the size of the | 331 // If we use border-box sizing we need to track changes in the size of the |
326 // content box. | 332 // content box. |
327 if (style.boxSizing() == EBoxSizing::kBorderBox) | 333 if (style.boxSizing() == EBoxSizing::kBorderBox) |
328 return true; | 334 return true; |
329 | 335 |
330 // No need to save old border box size if we can use size of the old paint | 336 // No need to save old border box size if we can use size of the old paint |
331 // rect as the old border box size in the next invalidation. | 337 // rect as the old border box size in the next invalidation. |
(...skipping 21 matching lines...) Expand all Loading... | |
353 } | 359 } |
354 return; | 360 return; |
355 } | 361 } |
356 | 362 |
357 PreviousBoxGeometries geometries = {m_box.size(), m_box.contentBoxRect(), | 363 PreviousBoxGeometries geometries = {m_box.size(), m_box.contentBoxRect(), |
358 m_box.layoutOverflowRect()}; | 364 m_box.layoutOverflowRect()}; |
359 previousBoxGeometriesMap().set(&m_box, geometries); | 365 previousBoxGeometriesMap().set(&m_box, geometries); |
360 m_box.getMutableForPainting().setHasPreviousBoxGeometries(true); | 366 m_box.getMutableForPainting().setHasPreviousBoxGeometries(true); |
361 } | 367 } |
362 | 368 |
369 static LayoutSize previousBorderBoxSizeInternal(const LayoutBox& box, | |
370 const LayoutSize& defaultSize) { | |
371 DCHECK(box.hasPreviousBoxGeometries() == | |
372 previousBoxGeometriesMap().contains(&box)); | |
373 if (box.hasPreviousBoxGeometries()) | |
374 return previousBoxGeometriesMap().get(&box).borderBoxSize; | |
375 return defaultSize; | |
376 } | |
377 | |
378 // This is used by ViewPaintInvalidator to get the previous border box size | |
379 // of the HTML element, before the HTML element is paint invalidated. | |
380 LayoutSize BoxPaintInvalidator::previousBorderBoxSize(const LayoutBox& box) { | |
chrishtr
2017/02/16 23:11:25
It's weird that there are two methods with the sam
Xianzhu
2017/02/16 23:39:35
Done.
| |
381 return previousBorderBoxSizeInternal(box, box.visualRect().size()); | |
382 } | |
383 | |
384 // This is used during paint invalidation of the m_box. PaintInvalidator has | |
385 // already updated m_box.visualRect() to the current value, so we need to use | |
386 // context.oldVisualRect as the default value. | |
363 LayoutSize BoxPaintInvalidator::previousBorderBoxSize() { | 387 LayoutSize BoxPaintInvalidator::previousBorderBoxSize() { |
364 DCHECK(m_box.hasPreviousBoxGeometries() == | 388 return previousBorderBoxSizeInternal(m_box, m_context.oldVisualRect.size()); |
365 previousBoxGeometriesMap().contains(&m_box)); | |
366 if (m_box.hasPreviousBoxGeometries()) | |
367 return previousBoxGeometriesMap().get(&m_box).borderBoxSize; | |
368 | |
369 // We didn't save the old border box size because it was the same as the size | |
370 // of oldVisualRect. | |
371 return m_context.oldVisualRect.size(); | |
372 } | 389 } |
373 | 390 |
374 LayoutRect BoxPaintInvalidator::previousContentBoxRect() { | 391 LayoutRect BoxPaintInvalidator::previousContentBoxRect() { |
375 DCHECK(m_box.hasPreviousBoxGeometries() == | 392 DCHECK(m_box.hasPreviousBoxGeometries() == |
376 previousBoxGeometriesMap().contains(&m_box)); | 393 previousBoxGeometriesMap().contains(&m_box)); |
377 return m_box.hasPreviousBoxGeometries() | 394 return m_box.hasPreviousBoxGeometries() |
378 ? previousBoxGeometriesMap().get(&m_box).contentBoxRect | 395 ? previousBoxGeometriesMap().get(&m_box).contentBoxRect |
379 : LayoutRect(); | 396 : LayoutRect(); |
380 } | 397 } |
381 | 398 |
382 LayoutRect BoxPaintInvalidator::previousLayoutOverflowRect() { | 399 LayoutRect BoxPaintInvalidator::previousLayoutOverflowRect() { |
383 DCHECK(m_box.hasPreviousBoxGeometries() == | 400 DCHECK(m_box.hasPreviousBoxGeometries() == |
384 previousBoxGeometriesMap().contains(&m_box)); | 401 previousBoxGeometriesMap().contains(&m_box)); |
385 return m_box.hasPreviousBoxGeometries() | 402 return m_box.hasPreviousBoxGeometries() |
386 ? previousBoxGeometriesMap().get(&m_box).layoutOverflowRect | 403 ? previousBoxGeometriesMap().get(&m_box).layoutOverflowRect |
387 : LayoutRect(); | 404 : LayoutRect(); |
388 } | 405 } |
389 | 406 |
390 } // namespace blink | 407 } // namespace blink |
OLD | NEW |