| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 Google 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 are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * 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 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 | 32 |
| 33 #include "core/editing/TextAffinity.h" | 33 #include "core/editing/TextAffinity.h" |
| 34 #include "core/editing/VisiblePosition.h" | 34 #include "core/editing/VisiblePosition.h" |
| 35 #include "core/editing/VisibleUnits.h" | 35 #include "core/editing/VisibleUnits.h" |
| 36 #include "core/layout/api/LineLayoutAPIShim.h" | 36 #include "core/layout/api/LineLayoutAPIShim.h" |
| 37 #include "core/layout/compositing/CompositedSelectionBound.h" | 37 #include "core/layout/compositing/CompositedSelectionBound.h" |
| 38 #include "core/paint/PaintLayer.h" | 38 #include "core/paint/PaintLayer.h" |
| 39 | 39 |
| 40 namespace blink { | 40 namespace blink { |
| 41 | 41 |
| 42 static inline LayoutObject* layoutObjectFromPosition(const Position& position) | 42 template <typename Strategy> |
| 43 static inline LayoutObject* layoutObjectFromPosition(const PositionTemplate<Stra
tegy>& position) |
| 43 { | 44 { |
| 44 DCHECK(position.isNotNull()); | 45 DCHECK(position.isNotNull()); |
| 45 Node* layoutObjectNode = nullptr; | 46 Node* layoutObjectNode = nullptr; |
| 46 switch (position.anchorType()) { | 47 switch (position.anchorType()) { |
| 47 case PositionAnchorType::OffsetInAnchor: | 48 case PositionAnchorType::OffsetInAnchor: |
| 48 layoutObjectNode = position.computeNodeAfterPosition(); | 49 layoutObjectNode = position.computeNodeAfterPosition(); |
| 49 if (!layoutObjectNode || !layoutObjectNode->layoutObject()) | 50 if (!layoutObjectNode || !layoutObjectNode->layoutObject()) |
| 50 layoutObjectNode = position.anchorNode()->lastChild(); | 51 layoutObjectNode = position.anchorNode()->lastChild(); |
| 51 break; | 52 break; |
| 52 | 53 |
| 53 case PositionAnchorType::BeforeAnchor: | 54 case PositionAnchorType::BeforeAnchor: |
| 54 case PositionAnchorType::AfterAnchor: | 55 case PositionAnchorType::AfterAnchor: |
| 55 break; | 56 break; |
| 56 | 57 |
| 57 case PositionAnchorType::BeforeChildren: | 58 case PositionAnchorType::BeforeChildren: |
| 58 layoutObjectNode = position.anchorNode()->firstChild(); | 59 layoutObjectNode = Strategy::firstChild(*position.anchorNode()); |
| 59 break; | 60 break; |
| 60 case PositionAnchorType::AfterChildren: | 61 case PositionAnchorType::AfterChildren: |
| 61 layoutObjectNode = position.anchorNode()->lastChild(); | 62 layoutObjectNode = Strategy::lastChild(*position.anchorNode()); |
| 62 break; | 63 break; |
| 63 } | 64 } |
| 64 if (!layoutObjectNode || !layoutObjectNode->layoutObject()) | 65 if (!layoutObjectNode || !layoutObjectNode->layoutObject()) |
| 65 layoutObjectNode = position.anchorNode(); | 66 layoutObjectNode = position.anchorNode(); |
| 66 return layoutObjectNode->layoutObject(); | 67 return layoutObjectNode->layoutObject(); |
| 67 } | 68 } |
| 68 | 69 |
| 69 RenderedPosition::RenderedPosition(const VisiblePosition& position) | 70 RenderedPosition::RenderedPosition(const VisiblePosition& position) |
| 70 : RenderedPosition(position.deepEquivalent(), position.affinity()) | 71 : RenderedPosition(position.deepEquivalent(), position.affinity()) |
| 71 { | 72 { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 88 InlineBoxPosition boxPosition = computeInlineBoxPosition(position, affinity)
; | 89 InlineBoxPosition boxPosition = computeInlineBoxPosition(position, affinity)
; |
| 89 m_inlineBox = boxPosition.inlineBox; | 90 m_inlineBox = boxPosition.inlineBox; |
| 90 m_offset = boxPosition.offsetInBox; | 91 m_offset = boxPosition.offsetInBox; |
| 91 if (m_inlineBox) | 92 if (m_inlineBox) |
| 92 m_layoutObject = LineLayoutAPIShim::layoutObjectFrom(m_inlineBox->getLin
eLayoutItem()); | 93 m_layoutObject = LineLayoutAPIShim::layoutObjectFrom(m_inlineBox->getLin
eLayoutItem()); |
| 93 else | 94 else |
| 94 m_layoutObject = layoutObjectFromPosition(position); | 95 m_layoutObject = layoutObjectFromPosition(position); |
| 95 } | 96 } |
| 96 | 97 |
| 97 RenderedPosition::RenderedPosition(const PositionInFlatTree& position, TextAffin
ity affinity) | 98 RenderedPosition::RenderedPosition(const PositionInFlatTree& position, TextAffin
ity affinity) |
| 98 : RenderedPosition(toPositionInDOMTree(position), affinity) | 99 : m_layoutObject(nullptr) |
| 100 , m_inlineBox(nullptr) |
| 101 , m_offset(0) |
| 102 , m_prevLeafChild(uncachedInlineBox()) |
| 103 , m_nextLeafChild(uncachedInlineBox()) |
| 99 { | 104 { |
| 105 if (position.isNull()) |
| 106 return; |
| 107 InlineBoxPosition boxPosition = computeInlineBoxPosition(position, affinity)
; |
| 108 m_inlineBox = boxPosition.inlineBox; |
| 109 m_offset = boxPosition.offsetInBox; |
| 110 if (m_inlineBox) |
| 111 m_layoutObject = LineLayoutAPIShim::layoutObjectFrom(m_inlineBox->getLin
eLayoutItem()); |
| 112 else |
| 113 m_layoutObject = layoutObjectFromPosition(position); |
| 100 } | 114 } |
| 101 | 115 |
| 102 InlineBox* RenderedPosition::prevLeafChild() const | 116 InlineBox* RenderedPosition::prevLeafChild() const |
| 103 { | 117 { |
| 104 if (m_prevLeafChild == uncachedInlineBox()) | 118 if (m_prevLeafChild == uncachedInlineBox()) |
| 105 m_prevLeafChild = m_inlineBox->prevLeafChildIgnoringLineBreak(); | 119 m_prevLeafChild = m_inlineBox->prevLeafChildIgnoringLineBreak(); |
| 106 return m_prevLeafChild; | 120 return m_prevLeafChild; |
| 107 } | 121 } |
| 108 | 122 |
| 109 InlineBox* RenderedPosition::nextLeafChild() const | 123 InlineBox* RenderedPosition::nextLeafChild() const |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 bool layoutObjectContainsPosition(LayoutObject* target, const Position& position
) | 285 bool layoutObjectContainsPosition(LayoutObject* target, const Position& position
) |
| 272 { | 286 { |
| 273 for (LayoutObject* layoutObject = layoutObjectFromPosition(position); layout
Object && layoutObject->node(); layoutObject = layoutObject->parent()) { | 287 for (LayoutObject* layoutObject = layoutObjectFromPosition(position); layout
Object && layoutObject->node(); layoutObject = layoutObject->parent()) { |
| 274 if (layoutObject == target) | 288 if (layoutObject == target) |
| 275 return true; | 289 return true; |
| 276 } | 290 } |
| 277 return false; | 291 return false; |
| 278 } | 292 } |
| 279 | 293 |
| 280 } // namespace blink | 294 } // namespace blink |
| OLD | NEW |