969 {
970 AXTreeUpdateState update_state(*this);
972
973
974
975
976 if (!ComputePendingChanges(
update, &update_state))
977 return false;
978
979
980
981 for (auto&& pair : update_state.node_id_to_pending_data) {
983 const std::unique_ptr<PendingStructureChanges>&
data = pair.second;
984 if (
data->DoesNodeExpectSubtreeOrNodeWillBeDestroyed()) {
986 if (
data->DoesNodeExpectSubtreeWillBeDestroyed())
987 NotifySubtreeWillBeReparentedOrDeleted(node, &update_state);
988 if (
data->DoesNodeExpectNodeWillBeDestroyed())
989 NotifyNodeWillBeReparentedOrDeleted(node, &update_state);
990 }
991 }
992 }
993
994
995
996
997
998
999 std::set<int32_t> notified_node_data_will_change;
1000 for (
size_t i =
update.nodes.size();
i-- > 0;) {
1001 const AXNodeData& new_data =
update.nodes[
i];
1002 const bool is_new_root =
1003 update_state.root_will_be_created && new_data.id ==
update.root_id;
1004 if (!is_new_root) {
1006 if (node && notified_node_data_will_change.insert(new_data.id).second)
1007 NotifyNodeDataWillChange(node->data(), new_data);
1008 }
1009 }
1010
1011
1012
1013
1015
1016
1017
1018
1019
1020
1021
1022 bool root_updated = false;
1026 if (cleared_node == root_) {
1027
1028
1029
1030 if (
update.root_id != old_root_id) {
1031
1032
1033 AXNode* old_root = root_;
1034 root_ = nullptr;
1035 DestroySubtree(old_root, &update_state);
1036 } else {
1037
1038
1039 root_updated = true;
1040 }
1041 }
1042
1043
1044
1045 if (root_) {
1046 for (auto* child : cleared_node->children())
1047 DestroySubtree(child, &update_state);
1048 std::vector<AXNode*> children;
1049 cleared_node->SwapChildren(&children);
1050 update_state.pending_nodes.insert(cleared_node->id());
1051 }
1052 }
1053 }
1054
1056
1057
1058
1059 if (
update.has_tree_data && data_ !=
update.tree_data) {
1060 update_state.old_tree_data = data_;
1061 data_ =
update.tree_data;
1062 }
1063
1064
1065 for (
size_t i = 0;
i <
update.nodes.size(); ++
i) {
1066 const bool is_new_root = update_state.root_will_be_created &&
1068 if (!UpdateNode(
update.nodes[
i], is_new_root, &update_state))
1069 return false;
1070 }
1071
1072 if (!root_) {
1073 error_ = "Tree has no root.";
1074 return false;
1075 }
1076
1077 if (!ValidatePendingChangesComplete(update_state))
1078 return false;
1079
1080
1081
1082
1083
1084 std::set<int32_t> table_ids_checked;
1085 for (
size_t i = 0;
i <
update.nodes.size(); ++
i) {
1087 while (node) {
1088 if (table_ids_checked.find(node->id()) != table_ids_checked.end())
1089 break;
1090
1091 const auto& table_info_entry = table_info_map_.find(node->id());
1092 if (table_info_entry != table_info_map_.end())
1093 table_info_entry->second->Invalidate();
1094 table_ids_checked.insert(node->id());
1095 node = node->parent();
1096 }
1097 }
1098
1099
1100 node_set_size_pos_in_set_info_map_.clear();
1101
1102 std::vector<AXTreeObserver::Change> changes;
1103 changes.reserve(
update.nodes.size());
1104 std::set<AXNode::AXID> visited_observer_changes;
1105 for (
size_t i = 0;
i <
update.nodes.size(); ++
i) {
1107 if (!node || !visited_observer_changes.emplace(
update.nodes[
i].id).second)
1108 continue;
1109
1110 bool is_new_node = update_state.IsCreatedNode(node);
1111 bool is_reparented_node = update_state.IsReparentedNode(node);
1112
1114 if (is_new_node) {
1115 if (is_reparented_node) {
1116
1117
1118
1119
1120 bool is_subtree = !node->parent() ||
1121 !update_state.IsCreatedNode(node->parent()) ||
1122 (node->parent() == root_ && root_updated);
1125 } else {
1126
1127
1128
1129
1130 bool is_subtree = !node->parent() ||
1131 !update_state.IsCreatedNode(node->parent()) ||
1132 update_state.IsRemovedNode(node->parent()) ||
1133 (node->parent() == root_ && root_updated);
1136 }
1137 }
1138 changes.push_back(AXTreeObserver::Change(node, change));
1139 }
1140
1141
1142
1143
1144 std::set<AXNode::AXID> updated_unignored_cached_values_ids;
1146 update_state.invalidate_unignored_cached_values_ids) {
1148 while (node && node->data().IsIgnored())
1149 node = node->parent();
1150 if (node && updated_unignored_cached_values_ids.insert(node->id()).second)
1151 node->UpdateUnignoredCachedValues();
1152 }
1153
1154
1156
1157
1158
1159
1160 if (update_state.old_tree_data) {
1161 for (AXTreeObserver* observer : observers_)
1162 observer->OnTreeDataChanged(this, *update_state.old_tree_data, data_);
1163 }
1164
1165
1166
1167 for (
AXNode::AXID node_id : update_state.removed_node_ids) {
1168 if (!update_state.IsCreatedNode(node_id))
1169 NotifyNodeHasBeenDeleted(node_id);
1170 }
1171
1172
1173
1175 NotifyNodeHasBeenReparentedOrCreated(
GetFromId(node_id), &update_state);
1176
1177
1178
1179 for (
AXNode::AXID node_data_changed_id : update_state.node_data_changed_ids) {
1180 AXNode* node =
GetFromId(node_data_changed_id);
1182
1183
1184
1185 const bool is_new_root = update_state.root_will_be_created &&
1186 node_data_changed_id ==
update.root_id;
1187 if (!is_new_root) {
1188 auto it = update_state.old_node_id_to_data.find(node_data_changed_id);
1189 if (it != update_state.old_node_id_to_data.end()) {
1190 const AXNodeData& old_node_data = it->second;
1191 NotifyNodeDataHasBeenChanged(node, old_node_data, node->data());
1192 }
1193 }
1194
1195
1196 for (AXTreeObserver* observer : observers_)
1197 observer->OnNodeChanged(this, node);
1198 }
1199
1200 for (AXTreeObserver* observer : observers_)
1201 observer->OnAtomicUpdateFinished(
this, root_->
id() != old_root_id, changes);
1202
1203 return true;
1204}
void SetTreeUpdateInProgressState(bool set_tree_update_value)