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

Unified 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/android/view_android.cc
diff --git a/ui/android/view_android.cc b/ui/android/view_android.cc
index 6d2d7c25e9a47b54caa33ca14cc37c25a5af7fcc..15e51a0042ca48b6eb5c29d0bbbc6cafdb9541a3 100644
--- a/ui/android/view_android.cc
+++ b/ui/android/view_android.cc
@@ -104,10 +104,8 @@
ScopedJavaLocalRef<jobject> ViewAndroid::GetEventForwarder() {
if (!event_forwarder_) {
- DCHECK(!RootPathHasEventForwarder(parent_))
- << "The view tree path already has an event forwarder.";
- DCHECK(!SubtreeHasEventForwarder(this))
- << "The view tree path already has an event forwarder.";
+ DCHECK(!ViewTreeHasEventForwarder(this))
+ << "Root of the ViewAndroid can have at most one handler.";
event_forwarder_.reset(new EventForwarder(this));
}
return event_forwarder_->GetJavaObject();
@@ -117,9 +115,8 @@
DCHECK(child);
DCHECK(std::find(children_.begin(), children_.end(), child) ==
children_.end());
- DCHECK(!RootPathHasEventForwarder(this) || !SubtreeHasEventForwarder(child))
- << "Some view tree path will have more than one event forwarder "
- "if the child is added.";
+ DCHECK(!SubtreeHasEventForwarder(child) || !ViewTreeHasEventForwarder(this))
+ << "Only one event handler is allowed.";
// The new child goes to the top, which is the end of the list.
children_.push_back(child);
@@ -129,21 +126,20 @@
}
// static
-bool ViewAndroid::RootPathHasEventForwarder(ViewAndroid* view) {
- while (view) {
- if (view->has_event_forwarder())
+bool ViewAndroid::ViewTreeHasEventForwarder(ViewAndroid* view) {
+ ViewAndroid* v = view;
+ do {
+ if (v->has_event_forwarder())
return true;
- view = view->parent_;
- }
-
- return false;
+ v = v->parent_;
+ } while (v);
+ return SubtreeHasEventForwarder(view);
}
// static
bool ViewAndroid::SubtreeHasEventForwarder(ViewAndroid* view) {
if (view->has_event_forwarder())
return true;
-
for (auto* child : view->children_) {
if (SubtreeHasEventForwarder(child))
return true;
« 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