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 <map> | 5 #include <map> |
6 | 6 |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "base/rand_util.h" | 8 #include "base/rand_util.h" |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 | 227 |
228 virtual void OnBoundsChanged(const gfx::Rect& previous_bounds) OVERRIDE; | 228 virtual void OnBoundsChanged(const gfx::Rect& previous_bounds) OVERRIDE; |
229 virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE; | 229 virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE; |
230 virtual bool OnMouseDragged(const ui::MouseEvent& event) OVERRIDE; | 230 virtual bool OnMouseDragged(const ui::MouseEvent& event) OVERRIDE; |
231 virtual void OnMouseReleased(const ui::MouseEvent& event) OVERRIDE; | 231 virtual void OnMouseReleased(const ui::MouseEvent& event) OVERRIDE; |
232 virtual void OnMouseEntered(const ui::MouseEvent& event) OVERRIDE; | 232 virtual void OnMouseEntered(const ui::MouseEvent& event) OVERRIDE; |
233 virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE; | 233 virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE; |
234 | 234 |
235 virtual ui::EventResult OnTouchEvent(ui::TouchEvent* event) OVERRIDE; | 235 virtual ui::EventResult OnTouchEvent(ui::TouchEvent* event) OVERRIDE; |
236 // Ignores GestureEvent by default. | 236 // Ignores GestureEvent by default. |
237 virtual ui::EventResult OnGestureEvent(ui::GestureEvent* event) OVERRIDE; | 237 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE; |
238 | 238 |
239 virtual void Paint(gfx::Canvas* canvas) OVERRIDE; | 239 virtual void Paint(gfx::Canvas* canvas) OVERRIDE; |
240 virtual void SchedulePaintInRect(const gfx::Rect& rect) OVERRIDE; | 240 virtual void SchedulePaintInRect(const gfx::Rect& rect) OVERRIDE; |
241 virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE; | 241 virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE; |
242 | 242 |
243 // OnBoundsChanged. | 243 // OnBoundsChanged. |
244 bool did_change_bounds_; | 244 bool did_change_bounds_; |
245 gfx::Rect new_bounds_; | 245 gfx::Rect new_bounds_; |
246 | 246 |
247 // MouseEvent. | 247 // MouseEvent. |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 virtual ui::EventResult OnTouchEvent(ui::TouchEvent* event) OVERRIDE; | 280 virtual ui::EventResult OnTouchEvent(ui::TouchEvent* event) OVERRIDE; |
281 }; | 281 }; |
282 | 282 |
283 // A view subclass that consumes all Gesture events for testing purposes. | 283 // A view subclass that consumes all Gesture events for testing purposes. |
284 class TestViewConsumeGesture : public TestView { | 284 class TestViewConsumeGesture : public TestView { |
285 public: | 285 public: |
286 TestViewConsumeGesture() : TestView() {} | 286 TestViewConsumeGesture() : TestView() {} |
287 virtual ~TestViewConsumeGesture() {} | 287 virtual ~TestViewConsumeGesture() {} |
288 | 288 |
289 protected: | 289 protected: |
290 virtual ui::EventResult OnGestureEvent(ui::GestureEvent* event) OVERRIDE { | 290 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE { |
291 last_gesture_event_type_ = event->type(); | 291 last_gesture_event_type_ = event->type(); |
292 location_.SetPoint(event->x(), event->y()); | 292 location_.SetPoint(event->x(), event->y()); |
293 return ui::ER_CONSUMED; | 293 event->StopPropagation(); |
294 } | 294 } |
295 | 295 |
296 private: | 296 private: |
297 DISALLOW_COPY_AND_ASSIGN(TestViewConsumeGesture); | 297 DISALLOW_COPY_AND_ASSIGN(TestViewConsumeGesture); |
298 }; | 298 }; |
299 | 299 |
300 // A view subclass that ignores all Gesture events. | 300 // A view subclass that ignores all Gesture events. |
301 class TestViewIgnoreGesture: public TestView { | 301 class TestViewIgnoreGesture: public TestView { |
302 public: | 302 public: |
303 TestViewIgnoreGesture() : TestView() {} | 303 TestViewIgnoreGesture() : TestView() {} |
304 virtual ~TestViewIgnoreGesture() {} | 304 virtual ~TestViewIgnoreGesture() {} |
305 | 305 |
306 private: | 306 private: |
307 virtual ui::EventResult OnGestureEvent(ui::GestureEvent* event) OVERRIDE { | 307 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE { |
308 return ui::ER_UNHANDLED; | |
309 } | 308 } |
310 | 309 |
311 DISALLOW_COPY_AND_ASSIGN(TestViewIgnoreGesture); | 310 DISALLOW_COPY_AND_ASSIGN(TestViewIgnoreGesture); |
312 }; | 311 }; |
313 | 312 |
314 // A view subclass that ignores all scroll-gesture events, but consume all other | 313 // A view subclass that ignores all scroll-gesture events, but consume all other |
315 // gesture events. | 314 // gesture events. |
316 class TestViewIgnoreScrollGestures : public TestViewConsumeGesture { | 315 class TestViewIgnoreScrollGestures : public TestViewConsumeGesture { |
317 public: | 316 public: |
318 TestViewIgnoreScrollGestures() {} | 317 TestViewIgnoreScrollGestures() {} |
319 virtual ~TestViewIgnoreScrollGestures() {} | 318 virtual ~TestViewIgnoreScrollGestures() {} |
320 | 319 |
321 private: | 320 private: |
322 virtual ui::EventResult OnGestureEvent(ui::GestureEvent* event) OVERRIDE { | 321 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE { |
323 if (event->IsScrollGestureEvent()) | 322 if (event->IsScrollGestureEvent()) |
324 return ui::ER_UNHANDLED; | 323 return; |
325 return TestViewConsumeGesture::OnGestureEvent(event); | 324 TestViewConsumeGesture::OnGestureEvent(event); |
326 } | 325 } |
327 | 326 |
328 DISALLOW_COPY_AND_ASSIGN(TestViewIgnoreScrollGestures); | 327 DISALLOW_COPY_AND_ASSIGN(TestViewIgnoreScrollGestures); |
329 }; | 328 }; |
330 | 329 |
331 //////////////////////////////////////////////////////////////////////////////// | 330 //////////////////////////////////////////////////////////////////////////////// |
332 // OnBoundsChanged | 331 // OnBoundsChanged |
333 //////////////////////////////////////////////////////////////////////////////// | 332 //////////////////////////////////////////////////////////////////////////////// |
334 | 333 |
335 void TestView::OnBoundsChanged(const gfx::Rect& previous_bounds) { | 334 void TestView::OnBoundsChanged(const gfx::Rect& previous_bounds) { |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
587 root->DispatchTouchEvent(&released); | 586 root->DispatchTouchEvent(&released); |
588 EXPECT_EQ(v2->last_touch_event_type_, ui::ET_TOUCH_RELEASED); | 587 EXPECT_EQ(v2->last_touch_event_type_, ui::ET_TOUCH_RELEASED); |
589 EXPECT_EQ(v2->location_.x(), -100); | 588 EXPECT_EQ(v2->location_.x(), -100); |
590 EXPECT_EQ(v2->location_.y(), -100); | 589 EXPECT_EQ(v2->location_.y(), -100); |
591 // Make sure v1 did not receive the event | 590 // Make sure v1 did not receive the event |
592 EXPECT_EQ(v1->last_touch_event_type_, 0); | 591 EXPECT_EQ(v1->last_touch_event_type_, 0); |
593 | 592 |
594 widget->CloseNow(); | 593 widget->CloseNow(); |
595 } | 594 } |
596 | 595 |
597 ui::EventResult TestView::OnGestureEvent(ui::GestureEvent* event) { | 596 void TestView::OnGestureEvent(ui::GestureEvent* event) { |
598 return ui::ER_UNHANDLED; | |
599 } | 597 } |
600 | 598 |
601 TEST_F(ViewTest, GestureEvent) { | 599 TEST_F(ViewTest, GestureEvent) { |
602 // Views hierarchy for non delivery of GestureEvent. | 600 // Views hierarchy for non delivery of GestureEvent. |
603 TestView* v1 = new TestViewConsumeGesture(); | 601 TestView* v1 = new TestViewConsumeGesture(); |
604 v1->SetBoundsRect(gfx::Rect(0, 0, 300, 300)); | 602 v1->SetBoundsRect(gfx::Rect(0, 0, 300, 300)); |
605 | 603 |
606 TestView* v2 = new TestViewConsumeGesture(); | 604 TestView* v2 = new TestViewConsumeGesture(); |
607 v2->SetBoundsRect(gfx::Rect(100, 100, 100, 100)); | 605 v2->SetBoundsRect(gfx::Rect(100, 100, 100, 100)); |
608 | 606 |
(...skipping 2782 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3391 // Set to non default value. | 3389 // Set to non default value. |
3392 v->layer()->set_scale_content(false); | 3390 v->layer()->set_scale_content(false); |
3393 scoped_ptr<ui::Layer> old_layer(v->RecreateLayer()); | 3391 scoped_ptr<ui::Layer> old_layer(v->RecreateLayer()); |
3394 ui::Layer* new_layer = v->layer(); | 3392 ui::Layer* new_layer = v->layer(); |
3395 EXPECT_FALSE(new_layer->scale_content()); | 3393 EXPECT_FALSE(new_layer->scale_content()); |
3396 } | 3394 } |
3397 | 3395 |
3398 #endif // USE_AURA | 3396 #endif // USE_AURA |
3399 | 3397 |
3400 } // namespace views | 3398 } // namespace views |
OLD | NEW |