| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2004, 2005, 2006 Apple Computer, Inc. All rights reserved. | 2 * Copyright (C) 2004, 2005, 2006 Apple Computer, 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 30 matching lines...) Expand all Loading... |
| 41 #include "wtf/unicode/CharacterNames.h" | 41 #include "wtf/unicode/CharacterNames.h" |
| 42 | 42 |
| 43 #ifndef NDEBUG | 43 #ifndef NDEBUG |
| 44 #include <stdio.h> | 44 #include <stdio.h> |
| 45 #endif | 45 #endif |
| 46 | 46 |
| 47 namespace WebCore { | 47 namespace WebCore { |
| 48 | 48 |
| 49 VisibleSelection::VisibleSelection() | 49 VisibleSelection::VisibleSelection() |
| 50 : m_affinity(DOWNSTREAM) | 50 : m_affinity(DOWNSTREAM) |
| 51 , m_changeObserver(0) | 51 , m_changeObserver(nullptr) |
| 52 , m_selectionType(NoSelection) | 52 , m_selectionType(NoSelection) |
| 53 , m_baseIsFirst(true) | 53 , m_baseIsFirst(true) |
| 54 , m_isDirectional(false) | 54 , m_isDirectional(false) |
| 55 { | 55 { |
| 56 } | 56 } |
| 57 | 57 |
| 58 VisibleSelection::VisibleSelection(const Position& pos, EAffinity affinity, bool
isDirectional) | 58 VisibleSelection::VisibleSelection(const Position& pos, EAffinity affinity, bool
isDirectional) |
| 59 : m_base(pos) | 59 : m_base(pos) |
| 60 , m_extent(pos) | 60 , m_extent(pos) |
| 61 , m_affinity(affinity) | 61 , m_affinity(affinity) |
| 62 , m_changeObserver(0) | 62 , m_changeObserver(nullptr) |
| 63 , m_isDirectional(isDirectional) | 63 , m_isDirectional(isDirectional) |
| 64 { | 64 { |
| 65 validate(); | 65 validate(); |
| 66 } | 66 } |
| 67 | 67 |
| 68 VisibleSelection::VisibleSelection(const Position& base, const Position& extent,
EAffinity affinity, bool isDirectional) | 68 VisibleSelection::VisibleSelection(const Position& base, const Position& extent,
EAffinity affinity, bool isDirectional) |
| 69 : m_base(base) | 69 : m_base(base) |
| 70 , m_extent(extent) | 70 , m_extent(extent) |
| 71 , m_affinity(affinity) | 71 , m_affinity(affinity) |
| 72 , m_changeObserver(0) | 72 , m_changeObserver(nullptr) |
| 73 , m_isDirectional(isDirectional) | 73 , m_isDirectional(isDirectional) |
| 74 { | 74 { |
| 75 validate(); | 75 validate(); |
| 76 } | 76 } |
| 77 | 77 |
| 78 VisibleSelection::VisibleSelection(const VisiblePosition& pos, bool isDirectiona
l) | 78 VisibleSelection::VisibleSelection(const VisiblePosition& pos, bool isDirectiona
l) |
| 79 : m_base(pos.deepEquivalent()) | 79 : m_base(pos.deepEquivalent()) |
| 80 , m_extent(pos.deepEquivalent()) | 80 , m_extent(pos.deepEquivalent()) |
| 81 , m_affinity(pos.affinity()) | 81 , m_affinity(pos.affinity()) |
| 82 , m_changeObserver(0) | 82 , m_changeObserver(nullptr) |
| 83 , m_isDirectional(isDirectional) | 83 , m_isDirectional(isDirectional) |
| 84 { | 84 { |
| 85 validate(); | 85 validate(); |
| 86 } | 86 } |
| 87 | 87 |
| 88 VisibleSelection::VisibleSelection(const VisiblePosition& base, const VisiblePos
ition& extent, bool isDirectional) | 88 VisibleSelection::VisibleSelection(const VisiblePosition& base, const VisiblePos
ition& extent, bool isDirectional) |
| 89 : m_base(base.deepEquivalent()) | 89 : m_base(base.deepEquivalent()) |
| 90 , m_extent(extent.deepEquivalent()) | 90 , m_extent(extent.deepEquivalent()) |
| 91 , m_affinity(base.affinity()) | 91 , m_affinity(base.affinity()) |
| 92 , m_changeObserver(0) | 92 , m_changeObserver(nullptr) |
| 93 , m_isDirectional(isDirectional) | 93 , m_isDirectional(isDirectional) |
| 94 { | 94 { |
| 95 validate(); | 95 validate(); |
| 96 } | 96 } |
| 97 | 97 |
| 98 VisibleSelection::VisibleSelection(const Range* range, EAffinity affinity, bool
isDirectional) | 98 VisibleSelection::VisibleSelection(const Range* range, EAffinity affinity, bool
isDirectional) |
| 99 : m_base(range->startPosition()) | 99 : m_base(range->startPosition()) |
| 100 , m_extent(range->endPosition()) | 100 , m_extent(range->endPosition()) |
| 101 , m_affinity(affinity) | 101 , m_affinity(affinity) |
| 102 , m_changeObserver(0) | 102 , m_changeObserver(nullptr) |
| 103 , m_isDirectional(isDirectional) | 103 , m_isDirectional(isDirectional) |
| 104 { | 104 { |
| 105 validate(); | 105 validate(); |
| 106 } | 106 } |
| 107 | 107 |
| 108 VisibleSelection::VisibleSelection(const VisibleSelection& other) | 108 VisibleSelection::VisibleSelection(const VisibleSelection& other) |
| 109 : m_base(other.m_base) | 109 : m_base(other.m_base) |
| 110 , m_extent(other.m_extent) | 110 , m_extent(other.m_extent) |
| 111 , m_start(other.m_start) | 111 , m_start(other.m_start) |
| 112 , m_end(other.m_end) | 112 , m_end(other.m_end) |
| 113 , m_affinity(other.m_affinity) | 113 , m_affinity(other.m_affinity) |
| 114 , m_changeObserver(0) // Observer is associated with only one VisibleSelecti
on, so this should not be copied. | 114 , m_changeObserver(nullptr) // Observer is associated with only one VisibleS
election, so this should not be copied. |
| 115 , m_selectionType(other.m_selectionType) | 115 , m_selectionType(other.m_selectionType) |
| 116 , m_baseIsFirst(other.m_baseIsFirst) | 116 , m_baseIsFirst(other.m_baseIsFirst) |
| 117 , m_isDirectional(other.m_isDirectional) | 117 , m_isDirectional(other.m_isDirectional) |
| 118 { | 118 { |
| 119 } | 119 } |
| 120 | 120 |
| 121 VisibleSelection& VisibleSelection::operator=(const VisibleSelection& other) | 121 VisibleSelection& VisibleSelection::operator=(const VisibleSelection& other) |
| 122 { | 122 { |
| 123 didChange(); | 123 didChange(); |
| 124 | 124 |
| 125 m_base = other.m_base; | 125 m_base = other.m_base; |
| 126 m_extent = other.m_extent; | 126 m_extent = other.m_extent; |
| 127 m_start = other.m_start; | 127 m_start = other.m_start; |
| 128 m_end = other.m_end; | 128 m_end = other.m_end; |
| 129 m_affinity = other.m_affinity; | 129 m_affinity = other.m_affinity; |
| 130 m_changeObserver = 0; | 130 m_changeObserver = nullptr; |
| 131 m_selectionType = other.m_selectionType; | 131 m_selectionType = other.m_selectionType; |
| 132 m_baseIsFirst = other.m_baseIsFirst; | 132 m_baseIsFirst = other.m_baseIsFirst; |
| 133 m_isDirectional = other.m_isDirectional; | 133 m_isDirectional = other.m_isDirectional; |
| 134 return *this; | 134 return *this; |
| 135 } | 135 } |
| 136 | 136 |
| 137 VisibleSelection::~VisibleSelection() | 137 VisibleSelection::~VisibleSelection() |
| 138 { | 138 { |
| 139 #if !ENABLE(OILPAN) |
| 139 didChange(); | 140 didChange(); |
| 141 #endif |
| 140 } | 142 } |
| 141 | 143 |
| 142 VisibleSelection VisibleSelection::selectionFromContentsOfNode(Node* node) | 144 VisibleSelection VisibleSelection::selectionFromContentsOfNode(Node* node) |
| 143 { | 145 { |
| 144 ASSERT(!editingIgnoresContent(node)); | 146 ASSERT(!editingIgnoresContent(node)); |
| 145 return VisibleSelection(firstPositionInNode(node), lastPositionInNode(node),
DOWNSTREAM); | 147 return VisibleSelection(firstPositionInNode(node), lastPositionInNode(node),
DOWNSTREAM); |
| 146 } | 148 } |
| 147 | 149 |
| 148 void VisibleSelection::setBase(const Position& position) | 150 void VisibleSelection::setBase(const Position& position) |
| 149 { | 151 { |
| (...skipping 594 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 744 | 746 |
| 745 void VisibleSelection::setChangeObserver(ChangeObserver& observer) | 747 void VisibleSelection::setChangeObserver(ChangeObserver& observer) |
| 746 { | 748 { |
| 747 ASSERT(!m_changeObserver); | 749 ASSERT(!m_changeObserver); |
| 748 m_changeObserver = &observer; | 750 m_changeObserver = &observer; |
| 749 } | 751 } |
| 750 | 752 |
| 751 void VisibleSelection::clearChangeObserver() | 753 void VisibleSelection::clearChangeObserver() |
| 752 { | 754 { |
| 753 ASSERT(m_changeObserver); | 755 ASSERT(m_changeObserver); |
| 754 m_changeObserver = 0; | 756 m_changeObserver = nullptr; |
| 755 } | 757 } |
| 756 | 758 |
| 757 void VisibleSelection::didChange() | 759 void VisibleSelection::didChange() |
| 758 { | 760 { |
| 759 if (m_changeObserver) | 761 if (m_changeObserver) |
| 760 m_changeObserver->didChangeVisibleSelection(); | 762 m_changeObserver->didChangeVisibleSelection(); |
| 761 } | 763 } |
| 762 | 764 |
| 765 void VisibleSelection::trace(Visitor* visitor) |
| 766 { |
| 767 visitor->trace(m_base); |
| 768 visitor->trace(m_extent); |
| 769 visitor->trace(m_start); |
| 770 visitor->trace(m_end); |
| 771 visitor->trace(m_changeObserver); |
| 772 } |
| 773 |
| 763 #ifndef NDEBUG | 774 #ifndef NDEBUG |
| 764 | 775 |
| 765 void VisibleSelection::debugPosition() const | 776 void VisibleSelection::debugPosition() const |
| 766 { | 777 { |
| 767 fprintf(stderr, "VisibleSelection ===============\n"); | 778 fprintf(stderr, "VisibleSelection ===============\n"); |
| 768 | 779 |
| 769 if (!m_start.anchorNode()) | 780 if (!m_start.anchorNode()) |
| 770 fputs("pos: null", stderr); | 781 fputs("pos: null", stderr); |
| 771 else if (m_start == m_end) { | 782 else if (m_start == m_end) { |
| 772 fprintf(stderr, "pos: %s ", m_start.anchorNode()->nodeName().utf8().da
ta()); | 783 fprintf(stderr, "pos: %s ", m_start.anchorNode()->nodeName().utf8().da
ta()); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 824 sel.showTreeForThis(); | 835 sel.showTreeForThis(); |
| 825 } | 836 } |
| 826 | 837 |
| 827 void showTree(const WebCore::VisibleSelection* sel) | 838 void showTree(const WebCore::VisibleSelection* sel) |
| 828 { | 839 { |
| 829 if (sel) | 840 if (sel) |
| 830 sel->showTreeForThis(); | 841 sel->showTreeForThis(); |
| 831 } | 842 } |
| 832 | 843 |
| 833 #endif | 844 #endif |
| OLD | NEW |