| OLD | NEW |
| 1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 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 "cc/trees/layer_tree_impl.h" | 5 #include "cc/trees/layer_tree_impl.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 1812 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1823 FindClosestMatchingLayer(screen_space_point, root_layer(), func, | 1823 FindClosestMatchingLayer(screen_space_point, root_layer(), func, |
| 1824 property_trees_.transform_tree, | 1824 property_trees_.transform_tree, |
| 1825 property_trees_.clip_tree, &state); | 1825 property_trees_.clip_tree, &state); |
| 1826 return state.closest_match; | 1826 return state.closest_match; |
| 1827 } | 1827 } |
| 1828 | 1828 |
| 1829 void LayerTreeImpl::RegisterSelection(const LayerSelection& selection) { | 1829 void LayerTreeImpl::RegisterSelection(const LayerSelection& selection) { |
| 1830 selection_ = selection; | 1830 selection_ = selection; |
| 1831 } | 1831 } |
| 1832 | 1832 |
| 1833 static ViewportSelectionBound ComputeViewportSelectionBound( | 1833 static gfx::SelectionBound ComputeViewportSelectionBound( |
| 1834 const LayerSelectionBound& layer_bound, | 1834 const LayerSelectionBound& layer_bound, |
| 1835 LayerImpl* layer, | 1835 LayerImpl* layer, |
| 1836 float device_scale_factor, | 1836 float device_scale_factor, |
| 1837 const TransformTree& transform_tree, | 1837 const TransformTree& transform_tree, |
| 1838 const ClipTree& clip_tree) { | 1838 const ClipTree& clip_tree) { |
| 1839 ViewportSelectionBound viewport_bound; | 1839 gfx::SelectionBound viewport_bound; |
| 1840 viewport_bound.type = layer_bound.type; | 1840 viewport_bound.set_type(layer_bound.type); |
| 1841 | 1841 |
| 1842 if (!layer || layer_bound.type == SELECTION_BOUND_EMPTY) | 1842 if (!layer || layer_bound.type == gfx::SelectionBound::EMPTY) |
| 1843 return viewport_bound; | 1843 return viewport_bound; |
| 1844 | 1844 |
| 1845 auto layer_top = gfx::PointF(layer_bound.edge_top); | 1845 auto layer_top = gfx::PointF(layer_bound.edge_top); |
| 1846 auto layer_bottom = gfx::PointF(layer_bound.edge_bottom); | 1846 auto layer_bottom = gfx::PointF(layer_bound.edge_bottom); |
| 1847 gfx::Transform screen_space_transform = layer->ScreenSpaceTransform(); | 1847 gfx::Transform screen_space_transform = layer->ScreenSpaceTransform(); |
| 1848 | 1848 |
| 1849 bool clipped = false; | 1849 bool clipped = false; |
| 1850 gfx::PointF screen_top = | 1850 gfx::PointF screen_top = |
| 1851 MathUtil::MapPoint(screen_space_transform, layer_top, &clipped); | 1851 MathUtil::MapPoint(screen_space_transform, layer_top, &clipped); |
| 1852 gfx::PointF screen_bottom = | 1852 gfx::PointF screen_bottom = |
| 1853 MathUtil::MapPoint(screen_space_transform, layer_bottom, &clipped); | 1853 MathUtil::MapPoint(screen_space_transform, layer_bottom, &clipped); |
| 1854 | 1854 |
| 1855 // MapPoint can produce points with NaN components (even when no inputs are | 1855 // MapPoint can produce points with NaN components (even when no inputs are |
| 1856 // NaN). Since consumers of ViewportSelectionBounds may round |edge_top| or | 1856 // NaN). Since consumers of gfx::SelectionBounds may round |edge_top| or |
| 1857 // |edge_bottom| (and since rounding will crash on NaN), we return an empty | 1857 // |edge_bottom| (and since rounding will crash on NaN), we return an empty |
| 1858 // bound instead. | 1858 // bound instead. |
| 1859 if (std::isnan(screen_top.x()) || std::isnan(screen_top.y()) || | 1859 if (std::isnan(screen_top.x()) || std::isnan(screen_top.y()) || |
| 1860 std::isnan(screen_bottom.x()) || std::isnan(screen_bottom.y())) | 1860 std::isnan(screen_bottom.x()) || std::isnan(screen_bottom.y())) |
| 1861 return ViewportSelectionBound(); | 1861 return gfx::SelectionBound(); |
| 1862 | 1862 |
| 1863 const float inv_scale = 1.f / device_scale_factor; | 1863 const float inv_scale = 1.f / device_scale_factor; |
| 1864 viewport_bound.edge_top = gfx::ScalePoint(screen_top, inv_scale); | 1864 viewport_bound.SetEdgeTop(gfx::ScalePoint(screen_top, inv_scale)); |
| 1865 viewport_bound.edge_bottom = gfx::ScalePoint(screen_bottom, inv_scale); | 1865 viewport_bound.SetEdgeBottom(gfx::ScalePoint(screen_bottom, inv_scale)); |
| 1866 | 1866 |
| 1867 // The bottom edge point is used for visibility testing as it is the logical | 1867 // The bottom edge point is used for visibility testing as it is the logical |
| 1868 // focal point for bound selection handles (this may change in the future). | 1868 // focal point for bound selection handles (this may change in the future). |
| 1869 // Shifting the visibility point fractionally inward ensures that neighboring | 1869 // Shifting the visibility point fractionally inward ensures that neighboring |
| 1870 // or logically coincident layers aligned to integral DPI coordinates will not | 1870 // or logically coincident layers aligned to integral DPI coordinates will not |
| 1871 // spuriously occlude the bound. | 1871 // spuriously occlude the bound. |
| 1872 gfx::Vector2dF visibility_offset = layer_top - layer_bottom; | 1872 gfx::Vector2dF visibility_offset = layer_top - layer_bottom; |
| 1873 visibility_offset.Scale(device_scale_factor / visibility_offset.Length()); | 1873 visibility_offset.Scale(device_scale_factor / visibility_offset.Length()); |
| 1874 gfx::PointF visibility_point = layer_bottom + visibility_offset; | 1874 gfx::PointF visibility_point = layer_bottom + visibility_offset; |
| 1875 if (visibility_point.x() <= 0) | 1875 if (visibility_point.x() <= 0) |
| 1876 visibility_point.set_x(visibility_point.x() + device_scale_factor); | 1876 visibility_point.set_x(visibility_point.x() + device_scale_factor); |
| 1877 visibility_point = | 1877 visibility_point = |
| 1878 MathUtil::MapPoint(screen_space_transform, visibility_point, &clipped); | 1878 MathUtil::MapPoint(screen_space_transform, visibility_point, &clipped); |
| 1879 | 1879 |
| 1880 float intersect_distance = 0.f; | 1880 float intersect_distance = 0.f; |
| 1881 viewport_bound.visible = PointHitsLayer( | 1881 viewport_bound.set_visible(PointHitsLayer( |
| 1882 layer, visibility_point, &intersect_distance, transform_tree, clip_tree); | 1882 layer, visibility_point, &intersect_distance, transform_tree, clip_tree)); |
| 1883 | 1883 |
| 1884 return viewport_bound; | 1884 return viewport_bound; |
| 1885 } | 1885 } |
| 1886 | 1886 |
| 1887 void LayerTreeImpl::GetViewportSelection(ViewportSelection* selection) { | 1887 void LayerTreeImpl::GetViewportSelection( |
| 1888 Selection<gfx::SelectionBound>* selection) { |
| 1888 DCHECK(selection); | 1889 DCHECK(selection); |
| 1889 | 1890 |
| 1890 selection->start = ComputeViewportSelectionBound( | 1891 selection->start = ComputeViewportSelectionBound( |
| 1891 selection_.start, | 1892 selection_.start, |
| 1892 selection_.start.layer_id ? LayerById(selection_.start.layer_id) : NULL, | 1893 selection_.start.layer_id ? LayerById(selection_.start.layer_id) : NULL, |
| 1893 device_scale_factor(), property_trees_.transform_tree, | 1894 device_scale_factor(), property_trees_.transform_tree, |
| 1894 property_trees_.clip_tree); | 1895 property_trees_.clip_tree); |
| 1895 selection->is_editable = selection_.is_editable; | 1896 selection->is_editable = selection_.is_editable; |
| 1896 selection->is_empty_text_form_control = selection_.is_empty_text_form_control; | 1897 selection->is_empty_text_form_control = selection_.is_empty_text_form_control; |
| 1897 if (selection->start.type == SELECTION_BOUND_CENTER || | 1898 if (selection->start.type() == gfx::SelectionBound::CENTER || |
| 1898 selection->start.type == SELECTION_BOUND_EMPTY) { | 1899 selection->start.type() == gfx::SelectionBound::EMPTY) { |
| 1899 selection->end = selection->start; | 1900 selection->end = selection->start; |
| 1900 } else { | 1901 } else { |
| 1901 selection->end = ComputeViewportSelectionBound( | 1902 selection->end = ComputeViewportSelectionBound( |
| 1902 selection_.end, | 1903 selection_.end, |
| 1903 selection_.end.layer_id ? LayerById(selection_.end.layer_id) : NULL, | 1904 selection_.end.layer_id ? LayerById(selection_.end.layer_id) : NULL, |
| 1904 device_scale_factor(), property_trees_.transform_tree, | 1905 device_scale_factor(), property_trees_.transform_tree, |
| 1905 property_trees_.clip_tree); | 1906 property_trees_.clip_tree); |
| 1906 } | 1907 } |
| 1907 } | 1908 } |
| 1908 | 1909 |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2055 } | 2056 } |
| 2056 | 2057 |
| 2057 void LayerTreeImpl::ResetAllChangeTracking() { | 2058 void LayerTreeImpl::ResetAllChangeTracking() { |
| 2058 layers_that_should_push_properties_.clear(); | 2059 layers_that_should_push_properties_.clear(); |
| 2059 for (auto* layer : *this) | 2060 for (auto* layer : *this) |
| 2060 layer->ResetChangeTracking(); | 2061 layer->ResetChangeTracking(); |
| 2061 property_trees_.ResetAllChangeTracking(); | 2062 property_trees_.ResetAllChangeTracking(); |
| 2062 } | 2063 } |
| 2063 | 2064 |
| 2064 } // namespace cc | 2065 } // namespace cc |
| OLD | NEW |