OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights | 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights |
3 * reserved. | 3 * reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
7 * are met: | 7 * are met: |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. 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 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 4087 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4098 } | 4098 } |
4099 | 4099 |
4100 Position SkipWhitespace(const Position& position) { | 4100 Position SkipWhitespace(const Position& position) { |
4101 return SkipWhitespaceAlgorithm(position); | 4101 return SkipWhitespaceAlgorithm(position); |
4102 } | 4102 } |
4103 | 4103 |
4104 PositionInFlatTree SkipWhitespace(const PositionInFlatTree& position) { | 4104 PositionInFlatTree SkipWhitespace(const PositionInFlatTree& position) { |
4105 return SkipWhitespaceAlgorithm(position); | 4105 return SkipWhitespaceAlgorithm(position); |
4106 } | 4106 } |
4107 | 4107 |
4108 static void CollectAbsoluteBoundsForRange(unsigned start, | 4108 template <typename Strategy> |
4109 unsigned end, | 4109 static Vector<FloatQuad> ComputeTextBounds( |
4110 const LayoutText& layout_text, | |
4111 Vector<IntRect>& rects) { | |
4112 layout_text.AbsoluteRectsForRange(rects, start, end); | |
4113 } | |
4114 | |
4115 static void CollectAbsoluteBoundsForRange(unsigned start, | |
4116 unsigned end, | |
4117 const LayoutText& layout_text, | |
4118 Vector<FloatQuad>& quads) { | |
4119 layout_text.AbsoluteQuadsForRange(quads, start, end); | |
4120 } | |
4121 | |
4122 template <typename RectType, typename Strategy> | |
4123 static Vector<RectType> ComputeTextBounds( | |
4124 const EphemeralRangeTemplate<Strategy>& range) { | 4110 const EphemeralRangeTemplate<Strategy>& range) { |
4125 const PositionTemplate<Strategy>& start_position = range.StartPosition(); | 4111 const PositionTemplate<Strategy>& start_position = range.StartPosition(); |
4126 const PositionTemplate<Strategy>& end_position = range.EndPosition(); | 4112 const PositionTemplate<Strategy>& end_position = range.EndPosition(); |
4127 Node* const start_container = start_position.ComputeContainerNode(); | 4113 Node* const start_container = start_position.ComputeContainerNode(); |
4128 DCHECK(start_container); | 4114 DCHECK(start_container); |
4129 Node* const end_container = end_position.ComputeContainerNode(); | 4115 Node* const end_container = end_position.ComputeContainerNode(); |
4130 DCHECK(end_container); | 4116 DCHECK(end_container); |
4131 | 4117 |
4132 Vector<RectType> result; | 4118 Vector<FloatQuad> result; |
4133 for (const Node& node : range.Nodes()) { | 4119 for (const Node& node : range.Nodes()) { |
4134 LayoutObject* const layout_object = node.GetLayoutObject(); | 4120 LayoutObject* const layout_object = node.GetLayoutObject(); |
4135 if (!layout_object || !layout_object->IsText()) | 4121 if (!layout_object || !layout_object->IsText()) |
4136 continue; | 4122 continue; |
4137 const LayoutText* layout_text = ToLayoutText(layout_object); | 4123 const LayoutText* layout_text = ToLayoutText(layout_object); |
4138 unsigned start_offset = | 4124 unsigned start_offset = |
4139 node == start_container ? start_position.OffsetInContainerNode() : 0; | 4125 node == start_container ? start_position.OffsetInContainerNode() : 0; |
4140 unsigned end_offset = node == end_container | 4126 unsigned end_offset = node == end_container |
4141 ? end_position.OffsetInContainerNode() | 4127 ? end_position.OffsetInContainerNode() |
4142 : std::numeric_limits<unsigned>::max(); | 4128 : std::numeric_limits<unsigned>::max(); |
4143 CollectAbsoluteBoundsForRange(start_offset, end_offset, *layout_text, | 4129 layout_text->AbsoluteQuadsForRange(result, start_offset, end_offset); |
4144 result); | |
4145 } | 4130 } |
4146 return result; | 4131 return result; |
4147 } | 4132 } |
4148 | 4133 |
4149 template <typename Strategy> | 4134 template <typename Strategy> |
4150 static IntRect ComputeTextRectTemplate( | 4135 static FloatRect ComputeTextRectTemplate( |
4151 const EphemeralRangeTemplate<Strategy>& range) { | 4136 const EphemeralRangeTemplate<Strategy>& range) { |
4152 IntRect result; | 4137 FloatRect result; |
4153 const Vector<IntRect>& rects = ComputeTextBounds<IntRect, Strategy>(range); | 4138 for (auto rect : ComputeTextBounds<Strategy>(range)) |
4154 for (const IntRect& rect : rects) | 4139 result.Unite(rect.BoundingBox()); |
4155 result.Unite(rect); | |
4156 return result; | 4140 return result; |
4157 } | 4141 } |
4158 | 4142 |
4159 IntRect ComputeTextRect(const EphemeralRange& range) { | 4143 IntRect ComputeTextRect(const EphemeralRange& range) { |
4160 return ComputeTextRectTemplate(range); | 4144 return EnclosingIntRect(ComputeTextRectTemplate(range)); |
4161 } | 4145 } |
4162 | 4146 |
4163 IntRect ComputeTextRect(const EphemeralRangeInFlatTree& range) { | 4147 IntRect ComputeTextRect(const EphemeralRangeInFlatTree& range) { |
4164 return ComputeTextRectTemplate(range); | 4148 return EnclosingIntRect(ComputeTextRectTemplate(range)); |
4165 } | 4149 } |
4166 | 4150 |
4167 Vector<FloatQuad> ComputeTextQuads(const EphemeralRange& range) { | 4151 Vector<FloatQuad> ComputeTextQuads(const EphemeralRange& range) { |
4168 return ComputeTextBounds<FloatQuad>(range); | 4152 return ComputeTextBounds(range); |
4169 } | 4153 } |
4170 | 4154 |
4171 } // namespace blink | 4155 } // namespace blink |
OLD | NEW |