OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/views/widget/root_view.h" | 5 #include "ui/views/widget/root_view.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 return ui::ER_CONSUMED; | 125 return ui::ER_CONSUMED; |
126 } | 126 } |
127 for (; v && v != this && !consumed; v = v->parent()) { | 127 for (; v && v != this && !consumed; v = v->parent()) { |
128 consumed = (event.type() == ui::ET_KEY_PRESSED) ? | 128 consumed = (event.type() == ui::ET_KEY_PRESSED) ? |
129 v->OnKeyPressed(event) : v->OnKeyReleased(event); | 129 v->OnKeyPressed(event) : v->OnKeyReleased(event); |
130 } | 130 } |
131 | 131 |
132 return consumed ? ui::ER_CONSUMED : ui::ER_UNHANDLED; | 132 return consumed ? ui::ER_CONSUMED : ui::ER_UNHANDLED; |
133 } | 133 } |
134 | 134 |
135 ui::EventResult RootView::DispatchScrollEvent(ui::ScrollEvent* event) { | 135 void RootView::DispatchScrollEvent(ui::ScrollEvent* event) { |
136 int result = ui::ER_UNHANDLED; | |
137 for (View* v = GetEventHandlerForPoint(event->location()); | 136 for (View* v = GetEventHandlerForPoint(event->location()); |
138 v && v != this && !(result & ui::ER_CONSUMED); v = v->parent()) | 137 v && v != this && !event->stopped_propagation(); v = v->parent()) { |
139 result |= v->OnScrollEvent(event); | 138 v->OnScrollEvent(event); |
140 return static_cast<ui::EventResult>(result); | 139 } |
141 } | 140 } |
142 | 141 |
143 ui::EventResult RootView::DispatchTouchEvent(ui::TouchEvent* event) { | 142 void RootView::DispatchTouchEvent(ui::TouchEvent* event) { |
144 // TODO: this looks all wrong. On a TOUCH_PRESSED we should figure out the | 143 // TODO: this looks all wrong. On a TOUCH_PRESSED we should figure out the |
145 // view and target that view with all touches with the same id until the | 144 // view and target that view with all touches with the same id until the |
146 // release (or keep it if captured). | 145 // release (or keep it if captured). |
147 | 146 |
148 // If touch_pressed_handler_ is non null, we are currently processing | 147 // If touch_pressed_handler_ is non null, we are currently processing |
149 // a touch down on the screen situation. In that case we send the | 148 // a touch down on the screen situation. In that case we send the |
150 // event to touch_pressed_handler_ | 149 // event to touch_pressed_handler_ |
151 ui::EventResult status = ui::ER_UNHANDLED; | |
152 | 150 |
153 if (touch_pressed_handler_) { | 151 if (touch_pressed_handler_) { |
154 ui::TouchEvent touch_event(*event, static_cast<View*>(this), | 152 ui::TouchEvent touch_event(*event, static_cast<View*>(this), |
155 touch_pressed_handler_); | 153 touch_pressed_handler_); |
156 status = touch_pressed_handler_->ProcessTouchEvent(&touch_event); | 154 touch_pressed_handler_->ProcessTouchEvent(&touch_event); |
157 return status; | 155 if (touch_event.handled()) |
| 156 event->SetHandled(); |
| 157 if (touch_event.stopped_propagation()) |
| 158 event->StopPropagation(); |
| 159 return; |
158 } | 160 } |
159 | 161 |
160 // Walk up the tree until we find a view that wants the touch event. | 162 // Walk up the tree until we find a view that wants the touch event. |
161 for (touch_pressed_handler_ = GetEventHandlerForPoint(event->location()); | 163 for (touch_pressed_handler_ = GetEventHandlerForPoint(event->location()); |
162 touch_pressed_handler_ && (touch_pressed_handler_ != this); | 164 touch_pressed_handler_ && (touch_pressed_handler_ != this); |
163 touch_pressed_handler_ = touch_pressed_handler_->parent()) { | 165 touch_pressed_handler_ = touch_pressed_handler_->parent()) { |
164 if (!touch_pressed_handler_->enabled()) { | 166 if (!touch_pressed_handler_->enabled()) { |
165 // Disabled views eat events but are treated as not handled. | 167 // Disabled views eat events but are treated as not handled. |
166 break; | 168 break; |
167 } | 169 } |
168 | 170 |
169 // See if this view wants to handle the touch | 171 // See if this view wants to handle the touch |
170 ui::TouchEvent touch_event(*event, static_cast<View*>(this), | 172 ui::TouchEvent touch_event(*event, static_cast<View*>(this), |
171 touch_pressed_handler_); | 173 touch_pressed_handler_); |
172 status = touch_pressed_handler_->ProcessTouchEvent(&touch_event); | 174 touch_pressed_handler_->ProcessTouchEvent(&touch_event); |
| 175 if (touch_event.handled()) |
| 176 event->SetHandled(); |
| 177 if (touch_event.stopped_propagation()) |
| 178 event->StopPropagation(); |
173 | 179 |
174 // The view could have removed itself from the tree when handling | 180 // The view could have removed itself from the tree when handling |
175 // OnTouchEvent(). So handle as per OnMousePressed. NB: we | 181 // OnTouchEvent(). So handle as per OnMousePressed. NB: we |
176 // assume that the RootView itself cannot be so removed. | 182 // assume that the RootView itself cannot be so removed. |
177 if (!touch_pressed_handler_) | 183 if (!touch_pressed_handler_) |
178 break; | 184 break; |
179 | 185 |
180 // The touch event wasn't processed. Go up the view hierarchy and dispatch | 186 // The touch event wasn't processed. Go up the view hierarchy and dispatch |
181 // the touch event. | 187 // the touch event. |
182 if (status == ui::ER_UNHANDLED) | 188 if (!event->handled()) |
183 continue; | 189 continue; |
184 | 190 |
185 // If a View consumed the event, that means future touch-events should go to | 191 // If a View consumed the event, that means future touch-events should go to |
186 // that View. If the event wasn't consumed, then reset the handler. | 192 // that View. If the event wasn't consumed, then reset the handler. |
187 if (!(status & ui::ER_CONSUMED)) | 193 if (!event->stopped_propagation()) |
188 touch_pressed_handler_ = NULL; | 194 touch_pressed_handler_ = NULL; |
189 | 195 |
190 return status; | 196 return; |
191 } | 197 } |
192 | 198 |
193 // Reset touch_pressed_handler_ to indicate that no processing is occurring. | 199 // Reset touch_pressed_handler_ to indicate that no processing is occurring. |
194 touch_pressed_handler_ = NULL; | 200 touch_pressed_handler_ = NULL; |
195 | 201 |
196 return status; | 202 return; |
197 } | 203 } |
198 | 204 |
199 void RootView::DispatchGestureEvent(ui::GestureEvent* event) { | 205 void RootView::DispatchGestureEvent(ui::GestureEvent* event) { |
200 if (gesture_handler_) { | 206 if (gesture_handler_) { |
201 // |gesture_handler_| (or |scroll_gesture_handler_|) can be deleted during | 207 // |gesture_handler_| (or |scroll_gesture_handler_|) can be deleted during |
202 // processing. | 208 // processing. |
203 View* handler = scroll_gesture_handler_ && | 209 View* handler = scroll_gesture_handler_ && |
204 (event->IsScrollGestureEvent() || event->IsFlingScrollEvent()) ? | 210 (event->IsScrollGestureEvent() || event->IsFlingScrollEvent()) ? |
205 scroll_gesture_handler_ : gesture_handler_; | 211 scroll_gesture_handler_ : gesture_handler_; |
206 ui::GestureEvent handler_event(*event, static_cast<View*>(this), handler); | 212 ui::GestureEvent handler_event(*event, static_cast<View*>(this), handler); |
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
619 } | 625 } |
620 | 626 |
621 void RootView::SetMouseLocationAndFlags(const ui::MouseEvent& event) { | 627 void RootView::SetMouseLocationAndFlags(const ui::MouseEvent& event) { |
622 last_mouse_event_flags_ = event.flags(); | 628 last_mouse_event_flags_ = event.flags(); |
623 last_mouse_event_x_ = event.x(); | 629 last_mouse_event_x_ = event.x(); |
624 last_mouse_event_y_ = event.y(); | 630 last_mouse_event_y_ = event.y(); |
625 } | 631 } |
626 | 632 |
627 } // namespace internal | 633 } // namespace internal |
628 } // namespace views | 634 } // namespace views |
OLD | NEW |