| 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 1964 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 bool toVisiblePosition(AXObject* obj, int offset, VisiblePosition& visibl
ePosition) |
| 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 |
| 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 visiblePosition = createVisiblePosition(Position(node, offset)); |
| 1999 return true; |
| 2000 } |
| 2001 |
| 2002 // If it is a text node, we need to call some utility functions that use a T
extIterator |
| 2003 // to walk the characters of the node and figure out the position correspond
ing to the |
| 2004 // visible character at position |offset|. |
| 2005 ContainerNode* parent = node->parentNode(); |
| 2006 if (!parent) |
| 2007 return false; |
| 2008 |
| 2009 VisiblePosition nodePosition = blink::visiblePositionBeforeNode(*node); |
| 2010 int nodeIndex = blink::indexForVisiblePosition(nodePosition, parent); |
| 2011 visiblePosition = blink::visiblePositionForIndex(nodeIndex + offset, parent)
; |
| 2012 return true; |
| 2013 } |
| 2014 |
| 1985 void AXLayoutObject::setSelection(const AXRange& selection) | 2015 void AXLayoutObject::setSelection(const AXRange& selection) |
| 1986 { | 2016 { |
| 1987 if (!getLayoutObject() || !selection.isValid()) | 2017 if (!getLayoutObject() || !selection.isValid()) |
| 1988 return; | 2018 return; |
| 1989 | 2019 |
| 1990 AXObject* anchorObject = selection.anchorObject ? | 2020 AXObject* anchorObject = selection.anchorObject ? |
| 1991 selection.anchorObject.get() : this; | 2021 selection.anchorObject.get() : this; |
| 1992 AXObject* focusObject = selection.focusObject ? | 2022 AXObject* focusObject = selection.focusObject ? |
| 1993 selection.focusObject.get() : this; | 2023 selection.focusObject.get() : this; |
| 1994 | 2024 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 2006 selection.anchorOffset, selection.focusOffset, | 2036 selection.anchorOffset, selection.focusOffset, |
| 2007 SelectionHasForwardDirection, NotDispatchSelectEvent); | 2037 SelectionHasForwardDirection, NotDispatchSelectEvent); |
| 2008 } else { | 2038 } else { |
| 2009 textControl->setSelectionRange( | 2039 textControl->setSelectionRange( |
| 2010 selection.focusOffset, selection.anchorOffset, | 2040 selection.focusOffset, selection.anchorOffset, |
| 2011 SelectionHasBackwardDirection, NotDispatchSelectEvent); | 2041 SelectionHasBackwardDirection, NotDispatchSelectEvent); |
| 2012 } | 2042 } |
| 2013 return; | 2043 return; |
| 2014 } | 2044 } |
| 2015 | 2045 |
| 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(); | 2046 LocalFrame* frame = getLayoutObject()->frame(); |
| 2032 if (!frame) | 2047 if (!frame) |
| 2033 return; | 2048 return; |
| 2034 | 2049 |
| 2035 // TODO(dglazkov): The use of updateStyleAndLayoutIgnorePendingStylesheets n
eeds to be audited. | 2050 // TODO(dglazkov): The use of updateStyleAndLayoutIgnorePendingStylesheets n
eeds to be audited. |
| 2036 // see http://crbug.com/590369 for more details. | 2051 // see http://crbug.com/590369 for more details. |
| 2037 // This callsite should probably move up the stack. | 2052 // This callsite should probably move up the stack. |
| 2038 frame->document()->updateStyleAndLayoutIgnorePendingStylesheets(); | 2053 frame->document()->updateStyleAndLayoutIgnorePendingStylesheets(); |
| 2039 | 2054 |
| 2040 // Set the selection based on visible positions, because the offsets in acce
ssibility nodes | 2055 // 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. | 2056 // are based on visible indexes, which often skips redundant whitespace, for
example. |
| 2042 VisiblePosition anchorVisiblePosition = anchorNode->isTextNode() | 2057 VisiblePosition anchorVisiblePosition, focusVisiblePosition; |
| 2043 ? blink::visiblePositionForIndex(selection.anchorOffset, anchorNode->par
entNode()) | 2058 if (!toVisiblePosition(anchorObject, selection.anchorOffset, anchorVisiblePo
sition)) |
| 2044 : createVisiblePosition(Position(anchorNode, selection.anchorOffset)); | 2059 return; |
| 2045 VisiblePosition focusVisiblePosition = focusNode->isTextNode() | 2060 if (!toVisiblePosition(focusObject, selection.focusOffset, focusVisiblePosit
ion)) |
| 2046 ? blink::visiblePositionForIndex(selection.focusOffset, focusNode->paren
tNode()) | 2061 return; |
| 2047 : createVisiblePosition(Position(focusNode, selection.focusOffset)); | |
| 2048 frame->selection().setSelection(VisibleSelection(anchorVisiblePosition, focu
sVisiblePosition)); | 2062 frame->selection().setSelection(VisibleSelection(anchorVisiblePosition, focu
sVisiblePosition)); |
| 2049 } | 2063 } |
| 2050 | 2064 |
| 2051 bool AXLayoutObject::isValidSelectionBound(const AXObject* boundObject) const | 2065 bool AXLayoutObject::isValidSelectionBound(const AXObject* boundObject) const |
| 2052 { | 2066 { |
| 2053 return getLayoutObject() && boundObject && !boundObject->isDetached() | 2067 return getLayoutObject() && boundObject && !boundObject->isDetached() |
| 2054 && boundObject->isAXLayoutObject() && boundObject->getLayoutObject() | 2068 && boundObject->isAXLayoutObject() && boundObject->getLayoutObject() |
| 2055 && boundObject->getLayoutObject()->frame() == getLayoutObject()->frame() | 2069 && boundObject->getLayoutObject()->frame() == getLayoutObject()->frame() |
| 2056 && &boundObject->axObjectCache() == &axObjectCache(); | 2070 && &boundObject->axObjectCache() == &axObjectCache(); |
| 2057 } | 2071 } |
| (...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2579 result.unite(labelRect); | 2593 result.unite(labelRect); |
| 2580 } | 2594 } |
| 2581 } | 2595 } |
| 2582 } | 2596 } |
| 2583 } | 2597 } |
| 2584 | 2598 |
| 2585 return result; | 2599 return result; |
| 2586 } | 2600 } |
| 2587 | 2601 |
| 2588 } // namespace blink | 2602 } // namespace blink |
| OLD | NEW |