OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2007, 2008, 2009 Apple Computer, Inc. | 2 * Copyright (C) 2007, 2008, 2009 Apple Computer, Inc. |
3 * Copyright (C) 2010, 2011 Google Inc. All rights reserved. | 3 * Copyright (C) 2010, 2011 Google Inc. All rights 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 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 if (const CSSValue* value = | 150 if (const CSSValue* value = |
151 backgroundColorValueInEffect(Range::commonAncestorContainer( | 151 backgroundColorValueInEffect(Range::commonAncestorContainer( |
152 range.startPosition().computeContainerNode(), | 152 range.startPosition().computeContainerNode(), |
153 range.endPosition().computeContainerNode()))) | 153 range.endPosition().computeContainerNode()))) |
154 style->setProperty(CSSPropertyBackgroundColor, value->cssText()); | 154 style->setProperty(CSSPropertyBackgroundColor, value->cssText()); |
155 } | 155 } |
156 | 156 |
157 return style; | 157 return style; |
158 } | 158 } |
159 | 159 |
160 static bool isUnicodeBidiNestedOrMultipleEmbeddings(CSSValueID valueID) { | |
161 return valueID == CSSValueEmbed || valueID == CSSValueBidiOverride || | |
162 valueID == CSSValueWebkitIsolate || | |
163 valueID == CSSValueWebkitIsolateOverride || | |
164 valueID == CSSValueWebkitPlaintext || valueID == CSSValueIsolate || | |
165 valueID == CSSValueIsolateOverride || valueID == CSSValuePlaintext; | |
166 } | |
167 | |
168 WritingDirection EditingStyleUtilities::textDirectionForSelection( | |
169 const VisibleSelection& selection, | |
170 EditingStyle* typingStyle, | |
171 bool& hasNestedOrMultipleEmbeddings) { | |
172 hasNestedOrMultipleEmbeddings = true; | |
173 | |
174 if (selection.isNone()) | |
175 return NaturalWritingDirection; | |
176 | |
177 Position position = mostForwardCaretPosition(selection.start()); | |
178 | |
179 Node* node = position.anchorNode(); | |
180 if (!node) | |
181 return NaturalWritingDirection; | |
182 | |
183 Position end; | |
184 if (selection.isRange()) { | |
185 end = mostBackwardCaretPosition(selection.end()); | |
186 | |
187 DCHECK(end.document()); | |
188 const EphemeralRange caretRange(position.parentAnchoredEquivalent(), | |
189 end.parentAnchoredEquivalent()); | |
190 for (Node& n : caretRange.nodes()) { | |
191 if (!n.isStyledElement()) | |
192 continue; | |
193 | |
194 CSSComputedStyleDeclaration* style = | |
195 CSSComputedStyleDeclaration::create(&n); | |
196 const CSSValue* unicodeBidi = | |
197 style->getPropertyCSSValue(CSSPropertyUnicodeBidi); | |
198 if (!unicodeBidi || !unicodeBidi->isIdentifierValue()) | |
199 continue; | |
200 | |
201 CSSValueID unicodeBidiValue = | |
202 toCSSIdentifierValue(unicodeBidi)->getValueID(); | |
203 if (isUnicodeBidiNestedOrMultipleEmbeddings(unicodeBidiValue)) | |
204 return NaturalWritingDirection; | |
205 } | |
206 } | |
207 | |
208 if (selection.isCaret()) { | |
209 WritingDirection direction; | |
210 if (typingStyle && typingStyle->textDirection(direction)) { | |
211 hasNestedOrMultipleEmbeddings = false; | |
212 return direction; | |
213 } | |
214 node = selection.visibleStart().deepEquivalent().anchorNode(); | |
215 } | |
216 DCHECK(node); | |
217 | |
218 // The selection is either a caret with no typing attributes or a range in | |
219 // which no embedding is added, so just use the start position to decide. | |
220 Node* block = enclosingBlock(node); | |
221 WritingDirection foundDirection = NaturalWritingDirection; | |
222 | |
223 for (Node& runner : NodeTraversal::inclusiveAncestorsOf(*node)) { | |
224 if (runner == block) | |
225 break; | |
226 if (!runner.isStyledElement()) | |
227 continue; | |
228 | |
229 Element* element = &toElement(runner); | |
230 CSSComputedStyleDeclaration* style = | |
231 CSSComputedStyleDeclaration::create(element); | |
232 const CSSValue* unicodeBidi = | |
233 style->getPropertyCSSValue(CSSPropertyUnicodeBidi); | |
234 if (!unicodeBidi || !unicodeBidi->isIdentifierValue()) | |
235 continue; | |
236 | |
237 CSSValueID unicodeBidiValue = | |
238 toCSSIdentifierValue(unicodeBidi)->getValueID(); | |
239 if (unicodeBidiValue == CSSValueNormal) | |
240 continue; | |
241 | |
242 if (unicodeBidiValue == CSSValueBidiOverride) | |
243 return NaturalWritingDirection; | |
244 | |
245 DCHECK(isEmbedOrIsolate(unicodeBidiValue)) << unicodeBidiValue; | |
246 const CSSValue* direction = | |
247 style->getPropertyCSSValue(CSSPropertyDirection); | |
248 if (!direction || !direction->isIdentifierValue()) | |
249 continue; | |
250 | |
251 int directionValue = toCSSIdentifierValue(direction)->getValueID(); | |
252 if (directionValue != CSSValueLtr && directionValue != CSSValueRtl) | |
253 continue; | |
254 | |
255 if (foundDirection != NaturalWritingDirection) | |
256 return NaturalWritingDirection; | |
257 | |
258 // In the range case, make sure that the embedding element persists until | |
259 // the end of the range. | |
260 if (selection.isRange() && !end.anchorNode()->isDescendantOf(element)) | |
261 return NaturalWritingDirection; | |
262 | |
263 foundDirection = directionValue == CSSValueLtr | |
264 ? LeftToRightWritingDirection | |
265 : RightToLeftWritingDirection; | |
266 } | |
267 hasNestedOrMultipleEmbeddings = false; | |
268 return foundDirection; | |
269 } | |
270 | |
271 bool EditingStyleUtilities::isTransparentColorValue(const CSSValue* cssValue) { | 160 bool EditingStyleUtilities::isTransparentColorValue(const CSSValue* cssValue) { |
272 if (!cssValue) | 161 if (!cssValue) |
273 return true; | 162 return true; |
274 if (cssValue->isColorValue()) | 163 if (cssValue->isColorValue()) |
275 return !toCSSColorValue(cssValue)->value().alpha(); | 164 return !toCSSColorValue(cssValue)->value().alpha(); |
276 if (!cssValue->isIdentifierValue()) | 165 if (!cssValue->isIdentifierValue()) |
277 return false; | 166 return false; |
278 return toCSSIdentifierValue(cssValue)->getValueID() == CSSValueTransparent; | 167 return toCSSIdentifierValue(cssValue)->getValueID() == CSSValueTransparent; |
279 } | 168 } |
280 | 169 |
(...skipping 16 matching lines...) Expand all Loading... |
297 for (Node* ancestor = node; ancestor; ancestor = ancestor->parentNode()) { | 186 for (Node* ancestor = node; ancestor; ancestor = ancestor->parentNode()) { |
298 CSSComputedStyleDeclaration* ancestorStyle = | 187 CSSComputedStyleDeclaration* ancestorStyle = |
299 CSSComputedStyleDeclaration::create(ancestor); | 188 CSSComputedStyleDeclaration::create(ancestor); |
300 if (!hasTransparentBackgroundColor(ancestorStyle)) | 189 if (!hasTransparentBackgroundColor(ancestorStyle)) |
301 return ancestorStyle->getPropertyCSSValue(CSSPropertyBackgroundColor); | 190 return ancestorStyle->getPropertyCSSValue(CSSPropertyBackgroundColor); |
302 } | 191 } |
303 return nullptr; | 192 return nullptr; |
304 } | 193 } |
305 | 194 |
306 } // namespace blink | 195 } // namespace blink |
OLD | NEW |