Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(60)

Side by Side Diff: third_party/WebKit/Source/core/editing/EditingUtilities.cpp

Issue 2184823004: [Editing][CodeHealth] Remove redundant Editabletype arguments in layoutObjectIsRichlyEditable (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved. 2 * Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 { 249 {
250 return comparePositions(a.position(), b.position()); 250 return comparePositions(a.position(), b.position());
251 } 251 }
252 252
253 int comparePositions(const VisiblePosition& a, const VisiblePosition& b) 253 int comparePositions(const VisiblePosition& a, const VisiblePosition& b)
254 { 254 {
255 return comparePositions(a.deepEquivalent(), b.deepEquivalent()); 255 return comparePositions(a.deepEquivalent(), b.deepEquivalent());
256 } 256 }
257 257
258 enum EditableLevel { Editable, RichlyEditable }; 258 enum EditableLevel { Editable, RichlyEditable };
259 static bool hasEditableStyle(const Node& node, EditableLevel editableLevel) 259 static bool hasEditableLevel(const Node& node, EditableLevel editableLevel)
260 { 260 {
261 if (node.isPseudoElement()) 261 if (node.isPseudoElement())
262 return false; 262 return false;
263 263
264 // Ideally we'd call DCHECK(!needsStyleRecalc()) here, but 264 // Ideally we'd call DCHECK(!needsStyleRecalc()) here, but
265 // ContainerNode::setFocus() calls setNeedsStyleRecalc(), so the assertion 265 // ContainerNode::setFocus() calls setNeedsStyleRecalc(), so the assertion
266 // would fire in the middle of Document::setFocusedNode(). 266 // would fire in the middle of Document::setFocusedNode().
267 267
268 for (const Node& ancestor : NodeTraversal::inclusiveAncestorsOf(node)) { 268 for (const Node& ancestor : NodeTraversal::inclusiveAncestorsOf(node)) {
269 if ((ancestor.isHTMLElement() || ancestor.isDocumentNode()) && ancestor. layoutObject()) { 269 if ((ancestor.isHTMLElement() || ancestor.isDocumentNode()) && ancestor. layoutObject()) {
270 switch (ancestor.layoutObject()->style()->userModify()) { 270 switch (ancestor.layoutObject()->style()->userModify()) {
271 case READ_ONLY: 271 case READ_ONLY:
272 return false; 272 return false;
273 case READ_WRITE: 273 case READ_WRITE:
274 return true; 274 return true;
275 case READ_WRITE_PLAINTEXT_ONLY: 275 case READ_WRITE_PLAINTEXT_ONLY:
276 return editableLevel != RichlyEditable; 276 return editableLevel != RichlyEditable;
277 } 277 }
278 NOTREACHED(); 278 NOTREACHED();
279 return false; 279 return false;
280 } 280 }
281 } 281 }
282 282
283 return false; 283 return false;
284 } 284 }
285 285
286 static bool isEditableToAccessibility(const Node& node, EditableLevel editableLe vel) 286 static bool hasAXEditableLevel(const Node& node, EditableLevel editableLevel)
287 { 287 {
288 if (blink::hasEditableStyle(node, editableLevel)) 288 if (hasEditableLevel(node, editableLevel))
289 return true; 289 return true;
290 290
291 // FIXME: Respect editableLevel for ARIA editable elements. 291 // FIXME: Respect editableLevel for ARIA editable elements.
292 if (editableLevel == RichlyEditable) 292 if (editableLevel == RichlyEditable)
293 return false; 293 return false;
294 294
295 // FIXME(dmazzoni): support ScopedAXObjectCache (crbug/489851). 295 // FIXME(dmazzoni): support ScopedAXObjectCache (crbug/489851).
296 if (AXObjectCache* cache = node.document().existingAXObjectCache()) 296 if (AXObjectCache* cache = node.document().existingAXObjectCache())
297 return cache->rootAXEditableElement(&node); 297 return cache->rootAXEditableElement(&node);
298 298
299 return false; 299 return false;
300 } 300 }
301 301
302 bool isContentEditable(const Node& node) 302 bool isContentEditable(const Node& node)
303 { 303 {
304 node.document().updateStyleAndLayoutTree(); 304 node.document().updateStyleAndLayoutTree();
305 return blink::hasEditableStyle(node, Editable); 305 return hasEditableLevel(node, Editable);
306 } 306 }
307 307
308 bool isContentRichlyEditable(const Node& node) 308 bool isContentRichlyEditable(const Node& node)
309 { 309 {
310 node.document().updateStyleAndLayoutTree(); 310 node.document().updateStyleAndLayoutTree();
311 return blink::hasEditableStyle(node, RichlyEditable); 311 return hasEditableLevel(node, RichlyEditable);
312 } 312 }
313 313
314 bool hasEditableStyle(const Node& node, EditableType editableType) 314 bool hasEditableStyle(const Node& node, EditableType editableType)
315 { 315 {
316 switch (editableType) { 316 switch (editableType) {
317 case ContentIsEditable: 317 case ContentIsEditable:
318 return blink::hasEditableStyle(node, Editable); 318 return hasEditableLevel(node, Editable);
319 case HasEditableAXRole: 319 case HasEditableAXRole:
320 return isEditableToAccessibility(node, Editable); 320 return hasAXEditableLevel(node, Editable);
321 } 321 }
322 NOTREACHED(); 322 NOTREACHED();
323 return false; 323 return false;
324 } 324 }
325 325
326 bool layoutObjectIsRichlyEditable(const Node& node, EditableType editableType) 326 bool hasRichlyEditableStyle(const Node& node)
327 { 327 {
328 switch (editableType) { 328 return hasEditableLevel(node, RichlyEditable);
329 case ContentIsEditable:
330 return blink::hasEditableStyle(node, RichlyEditable);
331 case HasEditableAXRole:
332 return isEditableToAccessibility(node, RichlyEditable);
333 }
334 NOTREACHED();
335 return false;
336 } 329 }
337 330
338 bool isRootEditableElement(const Node& node) 331 bool isRootEditableElement(const Node& node)
339 { 332 {
340 return hasEditableStyle(node) && node.isElementNode() && (!node.parentNode() || !hasEditableStyle(*node.parentNode()) 333 return hasEditableStyle(node) && node.isElementNode() && (!node.parentNode() || !hasEditableStyle(*node.parentNode())
341 || !node.parentNode()->isElementNode() || &node == node.document().body( )); 334 || !node.parentNode()->isElementNode() || &node == node.document().body( ));
342 } 335 }
343 336
344 Element* rootEditableElement(const Node& node) 337 Element* rootEditableElement(const Node& node)
345 { 338 {
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
428 421
429 bool isRichlyEditablePosition(const Position& p) 422 bool isRichlyEditablePosition(const Position& p)
430 { 423 {
431 Node* node = p.anchorNode(); 424 Node* node = p.anchorNode();
432 if (!node) 425 if (!node)
433 return false; 426 return false;
434 427
435 if (isDisplayInsideTable(node)) 428 if (isDisplayInsideTable(node))
436 node = node->parentNode(); 429 node = node->parentNode();
437 430
438 return layoutObjectIsRichlyEditable(*node); 431 return hasRichlyEditableStyle(*node);
439 } 432 }
440 433
441 Element* rootEditableElementOf(const Position& p, EditableType editableType) 434 Element* rootEditableElementOf(const Position& p, EditableType editableType)
442 { 435 {
443 Node* node = p.computeContainerNode(); 436 Node* node = p.computeContainerNode();
444 if (!node) 437 if (!node)
445 return 0; 438 return 0;
446 439
447 if (isDisplayInsideTable(node)) 440 if (isDisplayInsideTable(node))
448 node = node->parentNode(); 441 node = node->parentNode();
(...skipping 1475 matching lines...) Expand 10 before | Expand all | Expand 10 after
1924 { 1917 {
1925 if (!RuntimeEnabledFeatures::inputEventEnabled()) 1918 if (!RuntimeEnabledFeatures::inputEventEnabled())
1926 return DispatchEventResult::NotCanceled; 1919 return DispatchEventResult::NotCanceled;
1927 if (!target) 1920 if (!target)
1928 return DispatchEventResult::NotCanceled; 1921 return DispatchEventResult::NotCanceled;
1929 InputEvent* beforeInputEvent = InputEvent::createBeforeInput(inputType, data , InputEvent::EventCancelable::IsCancelable, InputEvent::EventIsComposing::NotCo mposing, ranges); 1922 InputEvent* beforeInputEvent = InputEvent::createBeforeInput(inputType, data , InputEvent::EventCancelable::IsCancelable, InputEvent::EventIsComposing::NotCo mposing, ranges);
1930 return target->dispatchEvent(beforeInputEvent); 1923 return target->dispatchEvent(beforeInputEvent);
1931 } 1924 }
1932 1925
1933 } // namespace blink 1926 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698