Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1418)

Side by Side Diff: ui/android/view_android.cc

Issue 2880583002: Revert of Refined DCHECK preventing multiple event forwarders in VA tree path (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/android/view_android.h ('k') | ui/android/view_android_unittests.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/android/view_android.h" 5 #include "ui/android/view_android.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/android/jni_android.h" 9 #include "base/android/jni_android.h"
10 #include "base/android/jni_string.h" 10 #include "base/android/jni_string.h"
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 JNIEnv* env = base::android::AttachCurrentThread(); 97 JNIEnv* env = base::android::AttachCurrentThread();
98 delegate_ = JavaObjectWeakGlobalRef(env, delegate); 98 delegate_ = JavaObjectWeakGlobalRef(env, delegate);
99 } 99 }
100 100
101 float ViewAndroid::GetDipScale() { 101 float ViewAndroid::GetDipScale() {
102 return ui::GetScaleFactorForNativeView(this); 102 return ui::GetScaleFactorForNativeView(this);
103 } 103 }
104 104
105 ScopedJavaLocalRef<jobject> ViewAndroid::GetEventForwarder() { 105 ScopedJavaLocalRef<jobject> ViewAndroid::GetEventForwarder() {
106 if (!event_forwarder_) { 106 if (!event_forwarder_) {
107 DCHECK(!RootPathHasEventForwarder(parent_)) 107 DCHECK(!ViewTreeHasEventForwarder(this))
108 << "The view tree path already has an event forwarder."; 108 << "Root of the ViewAndroid can have at most one handler.";
109 DCHECK(!SubtreeHasEventForwarder(this))
110 << "The view tree path already has an event forwarder.";
111 event_forwarder_.reset(new EventForwarder(this)); 109 event_forwarder_.reset(new EventForwarder(this));
112 } 110 }
113 return event_forwarder_->GetJavaObject(); 111 return event_forwarder_->GetJavaObject();
114 } 112 }
115 113
116 void ViewAndroid::AddChild(ViewAndroid* child) { 114 void ViewAndroid::AddChild(ViewAndroid* child) {
117 DCHECK(child); 115 DCHECK(child);
118 DCHECK(std::find(children_.begin(), children_.end(), child) == 116 DCHECK(std::find(children_.begin(), children_.end(), child) ==
119 children_.end()); 117 children_.end());
120 DCHECK(!RootPathHasEventForwarder(this) || !SubtreeHasEventForwarder(child)) 118 DCHECK(!SubtreeHasEventForwarder(child) || !ViewTreeHasEventForwarder(this))
121 << "Some view tree path will have more than one event forwarder " 119 << "Only one event handler is allowed.";
122 "if the child is added.";
123 120
124 // The new child goes to the top, which is the end of the list. 121 // The new child goes to the top, which is the end of the list.
125 children_.push_back(child); 122 children_.push_back(child);
126 if (child->parent_) 123 if (child->parent_)
127 child->RemoveFromParent(); 124 child->RemoveFromParent();
128 child->parent_ = this; 125 child->parent_ = this;
129 } 126 }
130 127
131 // static 128 // static
132 bool ViewAndroid::RootPathHasEventForwarder(ViewAndroid* view) { 129 bool ViewAndroid::ViewTreeHasEventForwarder(ViewAndroid* view) {
133 while (view) { 130 ViewAndroid* v = view;
134 if (view->has_event_forwarder()) 131 do {
132 if (v->has_event_forwarder())
135 return true; 133 return true;
136 view = view->parent_; 134 v = v->parent_;
137 } 135 } while (v);
138 136 return SubtreeHasEventForwarder(view);
139 return false;
140 } 137 }
141 138
142 // static 139 // static
143 bool ViewAndroid::SubtreeHasEventForwarder(ViewAndroid* view) { 140 bool ViewAndroid::SubtreeHasEventForwarder(ViewAndroid* view) {
144 if (view->has_event_forwarder()) 141 if (view->has_event_forwarder())
145 return true; 142 return true;
146
147 for (auto* child : view->children_) { 143 for (auto* child : view->children_) {
148 if (SubtreeHasEventForwarder(child)) 144 if (SubtreeHasEventForwarder(child))
149 return true; 145 return true;
150 } 146 }
151 return false; 147 return false;
152 } 148 }
153 149
154 void ViewAndroid::MoveToFront(ViewAndroid* child) { 150 void ViewAndroid::MoveToFront(ViewAndroid* child) {
155 DCHECK(child); 151 DCHECK(child);
156 auto it = std::find(children_.begin(), children_.end(), child); 152 auto it = std::find(children_.begin(), children_.end(), child);
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 matched = bound.Contains(e->GetX(0), e->GetY(0)); 332 matched = bound.Contains(e->GetX(0), e->GetY(0));
337 } 333 }
338 if (matched && child->HitTest(send_to_client, *e)) 334 if (matched && child->HitTest(send_to_client, *e))
339 return true; 335 return true;
340 } 336 }
341 } 337 }
342 return false; 338 return false;
343 } 339 }
344 340
345 } // namespace ui 341 } // namespace ui
OLDNEW
« no previous file with comments | « ui/android/view_android.h ('k') | ui/android/view_android_unittests.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698