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