Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 1955 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1966 return toAXLayoutObject(axObject); | 1966 return toAXLayoutObject(axObject); |
| 1967 | 1967 |
| 1968 return nullptr; | 1968 return nullptr; |
| 1969 } | 1969 } |
| 1970 | 1970 |
| 1971 | 1971 |
| 1972 // | 1972 // |
| 1973 // Modify or take an action on an object. | 1973 // Modify or take an action on an object. |
| 1974 // | 1974 // |
| 1975 | 1975 |
| 1976 // Convert from an accessible object and offset to a VisiblePosition. | |
| 1977 static VisiblePosition toVisiblePosition(AXObject* obj, int offset) | |
| 1978 { | |
| 1979 // First walk up until we find an accessible object with an associated node. | |
| 1980 AXObject* runner = obj; | |
| 1981 Node* node = nullptr; | |
| 1982 while (runner && !node) { | |
| 1983 node = runner->getNode(); | |
| 1984 runner = runner->parentObject(); | |
| 1985 } | |
| 1986 | |
| 1987 if (!node) | |
| 1988 return VisiblePosition(); | |
| 1989 | |
| 1990 // If it's not a text node, no conversion is necessary, just create a Visibl ePosition | |
| 1991 // with this node and offset. | |
| 1992 if (!node->isTextNode()) | |
| 1993 return createVisiblePosition(Position(node, offset)); | |
| 1994 | |
| 1995 // If it is a text node, we need to call some utility functions that use a T extIterator | |
| 1996 // to walk the characters of the node and figure out the position correspond ing to the | |
| 1997 // visible character at position |offset|. | |
| 1998 ContainerNode* parent = node->parentNode(); | |
| 1999 if (!parent) | |
| 2000 return VisiblePosition(); | |
| 2001 | |
| 2002 VisiblePosition nodePosition = blink::visiblePositionBeforeNode(*node); | |
| 2003 int nodeIndex = blink::indexForVisiblePosition(nodePosition, parent); | |
| 2004 return blink::visiblePositionForIndex(nodeIndex + offset, parent); | |
| 2005 } | |
| 2006 | |
| 1976 void AXLayoutObject::setSelection(const AXRange& selection) | 2007 void AXLayoutObject::setSelection(const AXRange& selection) |
| 1977 { | 2008 { |
| 1978 if (!getLayoutObject() || !selection.isValid()) | 2009 if (!getLayoutObject() || !selection.isValid()) |
| 1979 return; | 2010 return; |
| 1980 | 2011 |
| 1981 AXObject* anchorObject = selection.anchorObject ? | 2012 AXObject* anchorObject = selection.anchorObject ? |
| 1982 selection.anchorObject.get() : this; | 2013 selection.anchorObject.get() : this; |
| 1983 AXObject* focusObject = selection.focusObject ? | 2014 AXObject* focusObject = selection.focusObject ? |
| 1984 selection.focusObject.get() : this; | 2015 selection.focusObject.get() : this; |
| 1985 | 2016 |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 1997 selection.anchorOffset, selection.focusOffset, | 2028 selection.anchorOffset, selection.focusOffset, |
| 1998 SelectionHasForwardDirection, NotDispatchSelectEvent); | 2029 SelectionHasForwardDirection, NotDispatchSelectEvent); |
| 1999 } else { | 2030 } else { |
| 2000 textControl->setSelectionRange( | 2031 textControl->setSelectionRange( |
| 2001 selection.focusOffset, selection.anchorOffset, | 2032 selection.focusOffset, selection.anchorOffset, |
| 2002 SelectionHasBackwardDirection, NotDispatchSelectEvent); | 2033 SelectionHasBackwardDirection, NotDispatchSelectEvent); |
| 2003 } | 2034 } |
| 2004 return; | 2035 return; |
| 2005 } | 2036 } |
| 2006 | 2037 |
| 2007 Node* anchorNode = nullptr; | |
| 2008 while (anchorObject && !anchorNode) { | |
| 2009 anchorNode = anchorObject->getNode(); | |
| 2010 anchorObject = anchorObject->parentObject(); | |
| 2011 } | |
| 2012 | |
| 2013 Node* focusNode = nullptr; | |
| 2014 while (focusObject && !focusNode) { | |
| 2015 focusNode = focusObject->getNode(); | |
| 2016 focusObject = focusObject->parentObject(); | |
| 2017 } | |
| 2018 | |
| 2019 if (!anchorNode || !focusNode) | |
| 2020 return; | |
| 2021 | |
| 2022 LocalFrame* frame = getLayoutObject()->frame(); | 2038 LocalFrame* frame = getLayoutObject()->frame(); |
| 2023 if (!frame) | 2039 if (!frame) |
| 2024 return; | 2040 return; |
| 2025 | 2041 |
| 2026 // TODO(dglazkov): The use of updateStyleAndLayoutIgnorePendingStylesheets n eeds to be audited. | 2042 // TODO(dglazkov): The use of updateStyleAndLayoutIgnorePendingStylesheets n eeds to be audited. |
| 2027 // see http://crbug.com/590369 for more details. | 2043 // see http://crbug.com/590369 for more details. |
| 2028 // This callsite should probably move up the stack. | 2044 // This callsite should probably move up the stack. |
| 2029 frame->document()->updateStyleAndLayoutIgnorePendingStylesheets(); | 2045 frame->document()->updateStyleAndLayoutIgnorePendingStylesheets(); |
| 2030 | 2046 |
| 2031 // Set the selection based on visible positions, because the offsets in acce ssibility nodes | 2047 // Set the selection based on visible positions, because the offsets in acce ssibility nodes |
| 2032 // are based on visible indexes, which often skips redundant whitespace, for example. | 2048 // are based on visible indexes, which often skips redundant whitespace, for example. |
| 2033 VisiblePosition anchorVisiblePosition = anchorNode->isTextNode() | 2049 VisiblePosition anchorVisiblePosition = toVisiblePosition(anchorObject, sele ction.anchorOffset); |
| 2034 ? blink::visiblePositionForIndex(selection.anchorOffset, anchorNode->par entNode()) | 2050 VisiblePosition focusVisiblePosition = toVisiblePosition(focusObject, select ion.focusOffset); |
| 2035 : createVisiblePosition(Position(anchorNode, selection.anchorOffset)); | 2051 if (anchorVisiblePosition.isNull() || focusVisiblePosition.isNull()) |
| 2036 VisiblePosition focusVisiblePosition = focusNode->isTextNode() | 2052 return; |
| 2037 ? blink::visiblePositionForIndex(selection.focusOffset, focusNode->paren tNode()) | 2053 |
| 2038 : createVisiblePosition(Position(focusNode, selection.focusOffset)); | |
| 2039 frame->selection().setSelection(VisibleSelection(anchorVisiblePosition, focu sVisiblePosition)); | 2054 frame->selection().setSelection(VisibleSelection(anchorVisiblePosition, focu sVisiblePosition)); |
|
yosin_UTC9
2016/07/27 07:36:37
Could you pass |Position| instead of |VisiblePosit
| |
| 2040 } | 2055 } |
| 2041 | 2056 |
| 2042 bool AXLayoutObject::isValidSelectionBound(const AXObject* boundObject) const | 2057 bool AXLayoutObject::isValidSelectionBound(const AXObject* boundObject) const |
| 2043 { | 2058 { |
| 2044 return getLayoutObject() && boundObject && !boundObject->isDetached() | 2059 return getLayoutObject() && boundObject && !boundObject->isDetached() |
| 2045 && boundObject->isAXLayoutObject() && boundObject->getLayoutObject() | 2060 && boundObject->isAXLayoutObject() && boundObject->getLayoutObject() |
| 2046 && boundObject->getLayoutObject()->frame() == getLayoutObject()->frame() | 2061 && boundObject->getLayoutObject()->frame() == getLayoutObject()->frame() |
| 2047 && &boundObject->axObjectCache() == &axObjectCache(); | 2062 && &boundObject->axObjectCache() == &axObjectCache(); |
| 2048 } | 2063 } |
| 2049 | 2064 |
| (...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2570 result.unite(labelRect); | 2585 result.unite(labelRect); |
| 2571 } | 2586 } |
| 2572 } | 2587 } |
| 2573 } | 2588 } |
| 2574 } | 2589 } |
| 2575 | 2590 |
| 2576 return result; | 2591 return result; |
| 2577 } | 2592 } |
| 2578 | 2593 |
| 2579 } // namespace blink | 2594 } // namespace blink |
| OLD | NEW |