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

Side by Side Diff: third_party/WebKit/Source/modules/accessibility/AXLayoutObject.cpp

Issue 2164813003: Fix visible position calculation in accessible setSelection (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Return null VisiblePosition Created 4 years, 5 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) 2008 Apple Inc. All rights reserved. 2 * Copyright (C) 2008 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 * 7 *
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 1964 matching lines...) Expand 10 before | Expand all | Expand 10 after
1975 return toAXLayoutObject(axObject); 1975 return toAXLayoutObject(axObject);
1976 1976
1977 return nullptr; 1977 return nullptr;
1978 } 1978 }
1979 1979
1980 1980
1981 // 1981 //
1982 // Modify or take an action on an object. 1982 // Modify or take an action on an object.
1983 // 1983 //
1984 1984
1985 // Convert from an accessible object and offset to a VisiblePosition.
1986 static VisiblePosition toVisiblePosition(AXObject* obj, int offset)
1987 {
1988 // First walk up until we find an accessible object with an associated node.
1989 Node* node = nullptr;
1990 while (obj && !node) {
1991 node = obj->getNode();
1992 obj = obj->parentObject();
1993 }
1994
yosin_UTC9 2016/07/27 01:31:14 Please add |DCHECK(node) << obj|. For ease of debu
dmazzoni 2016/07/27 06:45:17 I changed to using a runner, good idea. Rather th
1995 // If it's not a text node, no conversion is necessary, just create a Visibl ePosition
1996 // with this node and offset.
1997 if (!node->isTextNode())
1998 return createVisiblePosition(Position(node, offset));
1999
2000 // If it is a text node, we need to call some utility functions that use a T extIterator
2001 // to walk the characters of the node and figure out the position correspond ing to the
2002 // visible character at position |offset|.
2003 ContainerNode* parent = node->parentNode();
2004 if (!parent)
2005 return VisiblePosition();
2006
2007 VisiblePosition nodePosition = blink::visiblePositionBeforeNode(*node);
yosin_UTC9 2016/07/27 01:31:14 I recommend to use |PlainTextRange|, which is used
dmazzoni 2016/07/27 06:45:17 I can't figure out how using PlainTextRange will m
yosin_UTC9 2016/07/27 07:36:37 I thinkg following code is identical to this seque
dmazzoni 2016/07/27 07:49:22 I just tried it, it doesn't work because it assume
yosin_UTC9 2016/07/27 09:20:48 I see, |offset| is visible offset in |node| instea
2008 int nodeIndex = blink::indexForVisiblePosition(nodePosition, parent);
2009 return blink::visiblePositionForIndex(nodeIndex + offset, parent);
2010 }
2011
1985 void AXLayoutObject::setSelection(const AXRange& selection) 2012 void AXLayoutObject::setSelection(const AXRange& selection)
1986 { 2013 {
1987 if (!getLayoutObject() || !selection.isValid()) 2014 if (!getLayoutObject() || !selection.isValid())
1988 return; 2015 return;
1989 2016
1990 AXObject* anchorObject = selection.anchorObject ? 2017 AXObject* anchorObject = selection.anchorObject ?
1991 selection.anchorObject.get() : this; 2018 selection.anchorObject.get() : this;
1992 AXObject* focusObject = selection.focusObject ? 2019 AXObject* focusObject = selection.focusObject ?
1993 selection.focusObject.get() : this; 2020 selection.focusObject.get() : this;
1994 2021
(...skipping 11 matching lines...) Expand all
2006 selection.anchorOffset, selection.focusOffset, 2033 selection.anchorOffset, selection.focusOffset,
2007 SelectionHasForwardDirection, NotDispatchSelectEvent); 2034 SelectionHasForwardDirection, NotDispatchSelectEvent);
2008 } else { 2035 } else {
2009 textControl->setSelectionRange( 2036 textControl->setSelectionRange(
2010 selection.focusOffset, selection.anchorOffset, 2037 selection.focusOffset, selection.anchorOffset,
2011 SelectionHasBackwardDirection, NotDispatchSelectEvent); 2038 SelectionHasBackwardDirection, NotDispatchSelectEvent);
2012 } 2039 }
2013 return; 2040 return;
2014 } 2041 }
2015 2042
2016 Node* anchorNode = nullptr;
2017 while (anchorObject && !anchorNode) {
2018 anchorNode = anchorObject->getNode();
2019 anchorObject = anchorObject->parentObject();
2020 }
2021
2022 Node* focusNode = nullptr;
2023 while (focusObject && !focusNode) {
2024 focusNode = focusObject->getNode();
2025 focusObject = focusObject->parentObject();
2026 }
2027
2028 if (!anchorNode || !focusNode)
2029 return;
2030
2031 LocalFrame* frame = getLayoutObject()->frame(); 2043 LocalFrame* frame = getLayoutObject()->frame();
2032 if (!frame) 2044 if (!frame)
2033 return; 2045 return;
2034 2046
2035 // TODO(dglazkov): The use of updateStyleAndLayoutIgnorePendingStylesheets n eeds to be audited. 2047 // TODO(dglazkov): The use of updateStyleAndLayoutIgnorePendingStylesheets n eeds to be audited.
2036 // see http://crbug.com/590369 for more details. 2048 // see http://crbug.com/590369 for more details.
2037 // This callsite should probably move up the stack. 2049 // This callsite should probably move up the stack.
2038 frame->document()->updateStyleAndLayoutIgnorePendingStylesheets(); 2050 frame->document()->updateStyleAndLayoutIgnorePendingStylesheets();
2039 2051
2040 // Set the selection based on visible positions, because the offsets in acce ssibility nodes 2052 // Set the selection based on visible positions, because the offsets in acce ssibility nodes
2041 // are based on visible indexes, which often skips redundant whitespace, for example. 2053 // are based on visible indexes, which often skips redundant whitespace, for example.
2042 VisiblePosition anchorVisiblePosition = anchorNode->isTextNode() 2054 VisiblePosition anchorVisiblePosition = toVisiblePosition(anchorObject, sele ction.anchorOffset);
2043 ? blink::visiblePositionForIndex(selection.anchorOffset, anchorNode->par entNode()) 2055 VisiblePosition focusVisiblePosition = toVisiblePosition(focusObject, select ion.focusOffset);
2044 : createVisiblePosition(Position(anchorNode, selection.anchorOffset)); 2056 if (anchorVisiblePosition.isNull() || focusVisiblePosition.isNull())
2045 VisiblePosition focusVisiblePosition = focusNode->isTextNode() 2057 return;
2046 ? blink::visiblePositionForIndex(selection.focusOffset, focusNode->paren tNode()) 2058
2047 : createVisiblePosition(Position(focusNode, selection.focusOffset));
2048 frame->selection().setSelection(VisibleSelection(anchorVisiblePosition, focu sVisiblePosition)); 2059 frame->selection().setSelection(VisibleSelection(anchorVisiblePosition, focu sVisiblePosition));
2049 } 2060 }
2050 2061
2051 bool AXLayoutObject::isValidSelectionBound(const AXObject* boundObject) const 2062 bool AXLayoutObject::isValidSelectionBound(const AXObject* boundObject) const
2052 { 2063 {
2053 return getLayoutObject() && boundObject && !boundObject->isDetached() 2064 return getLayoutObject() && boundObject && !boundObject->isDetached()
2054 && boundObject->isAXLayoutObject() && boundObject->getLayoutObject() 2065 && boundObject->isAXLayoutObject() && boundObject->getLayoutObject()
2055 && boundObject->getLayoutObject()->frame() == getLayoutObject()->frame() 2066 && boundObject->getLayoutObject()->frame() == getLayoutObject()->frame()
2056 && &boundObject->axObjectCache() == &axObjectCache(); 2067 && &boundObject->axObjectCache() == &axObjectCache();
2057 } 2068 }
(...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after
2579 result.unite(labelRect); 2590 result.unite(labelRect);
2580 } 2591 }
2581 } 2592 }
2582 } 2593 }
2583 } 2594 }
2584 2595
2585 return result; 2596 return result;
2586 } 2597 }
2587 2598
2588 } // namespace blink 2599 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698