| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2006, 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2006, 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 * 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 return true; | 45 return true; |
| 46 } | 46 } |
| 47 | 47 |
| 48 // This needs to be static so it can be called by canIncreaseSelectionListLevel
and canDecreaseSelectionListLevel | 48 // This needs to be static so it can be called by canIncreaseSelectionListLevel
and canDecreaseSelectionListLevel |
| 49 static bool getStartEndListChildren(const VisibleSelection& selection, Handle<No
de>& start, Handle<Node>& end) | 49 static bool getStartEndListChildren(const VisibleSelection& selection, Handle<No
de>& start, Handle<Node>& end) |
| 50 { | 50 { |
| 51 if (selection.isNone()) | 51 if (selection.isNone()) |
| 52 return false; | 52 return false; |
| 53 | 53 |
| 54 // start must be in a list child | 54 // start must be in a list child |
| 55 Handle<Node> startListChild = adoptRawResult(enclosingListChild(selection.st
art().anchorNode().handle().raw())); | 55 Handle<Node> startListChild = enclosingListChild(selection.start().anchorNod
e()); |
| 56 if (!startListChild) | 56 if (!startListChild) |
| 57 return false; | 57 return false; |
| 58 | 58 |
| 59 // end must be in a list child | 59 // end must be in a list child |
| 60 Handle<Node> endListChild = selection.isRange() ? adoptRawResult(enclosingLi
stChild(selection.end().anchorNode().handle().raw())) : Result<Node>(startListCh
ild); | 60 Handle<Node> endListChild = selection.isRange() ? enclosingListChild(selecti
on.end().anchorNode()).handle() : startListChild; |
| 61 if (!endListChild) | 61 if (!endListChild) |
| 62 return false; | 62 return false; |
| 63 | 63 |
| 64 // For a range selection we want the following behavior: | 64 // For a range selection we want the following behavior: |
| 65 // - the start and end must be within the same overall list | 65 // - the start and end must be within the same overall list |
| 66 // - the start must be at or above the level of the rest of the range | 66 // - the start must be at or above the level of the rest of the range |
| 67 // - if the end is anywhere in a sublist lower than start, the whole su
blist gets moved | 67 // - if the end is anywhere in a sublist lower than start, the whole su
blist gets moved |
| 68 // In terms of this function, this means: | 68 // In terms of this function, this means: |
| 69 // - endListChild must start out being be a sibling of startListChild,
or be in a | 69 // - endListChild must start out being be a sibling of startListChild,
or be in a |
| 70 // sublist of startListChild or a sibling | 70 // sublist of startListChild or a sibling |
| 71 // - if endListChild is in a sublist of startListChild or a sibling, it
must be adjusted | 71 // - if endListChild is in a sublist of startListChild or a sibling, it
must be adjusted |
| 72 // to be the ancestor that is startListChild or its sibling | 72 // to be the ancestor that is startListChild or its sibling |
| 73 while (startListChild->parentNode() != endListChild->parentNode()) { | 73 while (startListChild->parentNode() != endListChild->parentNode()) { |
| 74 endListChild = endListChild->parentNode(); | 74 endListChild = endListChild->parentNode(); |
| 75 if (!endListChild) | 75 if (!endListChild) |
| 76 return false; | 76 return false; |
| 77 } | 77 } |
| 78 | 78 |
| 79 // if the selection ends on a list item with a sublist, include the entire s
ublist | 79 // if the selection ends on a list item with a sublist, include the entire s
ublist |
| 80 if (endListChild->renderer()->isListItem()) { | 80 if (endListChild->renderer()->isListItem()) { |
| 81 RenderObject* r = endListChild->renderer()->nextSibling(); | 81 RenderObject* r = endListChild->renderer()->nextSibling(); |
| 82 if (r && isListElement(r->node().handle().raw())) | 82 if (r && isListElement(r->node())) |
| 83 endListChild = r->node(); | 83 endListChild = r->node(); |
| 84 } | 84 } |
| 85 | 85 |
| 86 start = startListChild; | 86 start = startListChild; |
| 87 end = endListChild; | 87 end = endListChild; |
| 88 return true; | 88 return true; |
| 89 } | 89 } |
| 90 | 90 |
| 91 void ModifySelectionListLevelCommand::insertSiblingNodeRangeBefore(const Handle<
Node>& startNode, const Handle<Node>& endNode, const Handle<Node>& refNode) | 91 void ModifySelectionListLevelCommand::insertSiblingNodeRangeBefore(const Handle<
Node>& startNode, const Handle<Node>& endNode, const Handle<Node>& refNode) |
| 92 { | 92 { |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 // - indicate whether the list node is new or pre-existing | 173 // - indicate whether the list node is new or pre-existing |
| 174 // - (silly) client specifies whether to return pre-existing list nodes | 174 // - (silly) client specifies whether to return pre-existing list nodes |
| 175 void IncreaseSelectionListLevelCommand::doApply() | 175 void IncreaseSelectionListLevelCommand::doApply() |
| 176 { | 176 { |
| 177 Handle<Node> startListChild; | 177 Handle<Node> startListChild; |
| 178 Handle<Node> endListChild; | 178 Handle<Node> endListChild; |
| 179 if (!canIncreaseListLevel(endingSelection(), startListChild, endListChild)) | 179 if (!canIncreaseListLevel(endingSelection(), startListChild, endListChild)) |
| 180 return; | 180 return; |
| 181 | 181 |
| 182 Handle<Node> previousItem = startListChild->renderer()->previousSibling()->n
ode(); | 182 Handle<Node> previousItem = startListChild->renderer()->previousSibling()->n
ode(); |
| 183 if (isListElement(previousItem.raw())) { | 183 if (isListElement(previousItem)) { |
| 184 // move nodes up into preceding list | 184 // move nodes up into preceding list |
| 185 appendSiblingNodeRange(startListChild, endListChild, toElement(previousI
tem)); | 185 appendSiblingNodeRange(startListChild, endListChild, toElement(previousI
tem)); |
| 186 m_listElement = previousItem; | 186 m_listElement = previousItem; |
| 187 } else { | 187 } else { |
| 188 // create a sublist for the preceding element and move nodes there | 188 // create a sublist for the preceding element and move nodes there |
| 189 Handle<Element> newParent; | 189 Handle<Element> newParent; |
| 190 switch (m_listType) { | 190 switch (m_listType) { |
| 191 case InheritedListType: | 191 case InheritedListType: |
| 192 newParent = startListChild->parentElement(); | 192 newParent = startListChild->parentElement(); |
| 193 if (newParent) | 193 if (newParent) |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 { | 242 { |
| 243 } | 243 } |
| 244 | 244 |
| 245 // This needs to be static so it can be called by canDecreaseSelectionListLevel | 245 // This needs to be static so it can be called by canDecreaseSelectionListLevel |
| 246 static bool canDecreaseListLevel(const VisibleSelection& selection, Handle<Node>
& start, Handle<Node>& end) | 246 static bool canDecreaseListLevel(const VisibleSelection& selection, Handle<Node>
& start, Handle<Node>& end) |
| 247 { | 247 { |
| 248 if (!getStartEndListChildren(selection, start, end)) | 248 if (!getStartEndListChildren(selection, start, end)) |
| 249 return false; | 249 return false; |
| 250 | 250 |
| 251 // there must be a destination list to move the items to | 251 // there must be a destination list to move the items to |
| 252 if (!isListElement(start->parentNode()->parentNode().handle().raw())) | 252 if (!isListElement(start->parentNode()->parentNode())) |
| 253 return false; | 253 return false; |
| 254 | 254 |
| 255 return true; | 255 return true; |
| 256 } | 256 } |
| 257 | 257 |
| 258 void DecreaseSelectionListLevelCommand::doApply() | 258 void DecreaseSelectionListLevelCommand::doApply() |
| 259 { | 259 { |
| 260 Handle<Node> startListChild; | 260 Handle<Node> startListChild; |
| 261 Handle<Node> endListChild; | 261 Handle<Node> endListChild; |
| 262 if (!canDecreaseListLevel(endingSelection(), startListChild, endListChild)) | 262 if (!canDecreaseListLevel(endingSelection(), startListChild, endListChild)) |
| (...skipping 27 matching lines...) Expand all Loading... |
| 290 } | 290 } |
| 291 | 291 |
| 292 void DecreaseSelectionListLevelCommand::decreaseSelectionListLevel(const Handle<
Document>& document) | 292 void DecreaseSelectionListLevelCommand::decreaseSelectionListLevel(const Handle<
Document>& document) |
| 293 { | 293 { |
| 294 ASSERT(document); | 294 ASSERT(document); |
| 295 ASSERT(document->frame()); | 295 ASSERT(document->frame()); |
| 296 applyCommand(create(document)); | 296 applyCommand(create(document)); |
| 297 } | 297 } |
| 298 | 298 |
| 299 } | 299 } |
| OLD | NEW |