| 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 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 accelerator_count_map_.clear(); | 225 accelerator_count_map_.clear(); |
| 226 } | 226 } |
| 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 void OnTouchEvent(ui::TouchEvent* event) OVERRIDE; |
| 236 // Ignores GestureEvent by default. | 236 // Ignores GestureEvent by default. |
| 237 virtual void 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_; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 270 std::map<ui::Accelerator, int> accelerator_count_map_; | 270 std::map<ui::Accelerator, int> accelerator_count_map_; |
| 271 }; | 271 }; |
| 272 | 272 |
| 273 // A view subclass that ignores all touch events for testing purposes. | 273 // A view subclass that ignores all touch events for testing purposes. |
| 274 class TestViewIgnoreTouch : public TestView { | 274 class TestViewIgnoreTouch : public TestView { |
| 275 public: | 275 public: |
| 276 TestViewIgnoreTouch() : TestView() {} | 276 TestViewIgnoreTouch() : TestView() {} |
| 277 virtual ~TestViewIgnoreTouch() {} | 277 virtual ~TestViewIgnoreTouch() {} |
| 278 | 278 |
| 279 private: | 279 private: |
| 280 virtual ui::EventResult OnTouchEvent(ui::TouchEvent* event) OVERRIDE; | 280 virtual void 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 void OnGestureEvent(ui::GestureEvent* event) OVERRIDE { | 290 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE { |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 467 ui::EF_LEFT_MOUSE_BUTTON); | 467 ui::EF_LEFT_MOUSE_BUTTON); |
| 468 root->OnMousePressed(pressed); | 468 root->OnMousePressed(pressed); |
| 469 EXPECT_EQ(0, v1->child_count()); | 469 EXPECT_EQ(0, v1->child_count()); |
| 470 | 470 |
| 471 widget->CloseNow(); | 471 widget->CloseNow(); |
| 472 } | 472 } |
| 473 | 473 |
| 474 //////////////////////////////////////////////////////////////////////////////// | 474 //////////////////////////////////////////////////////////////////////////////// |
| 475 // TouchEvent | 475 // TouchEvent |
| 476 //////////////////////////////////////////////////////////////////////////////// | 476 //////////////////////////////////////////////////////////////////////////////// |
| 477 ui::EventResult TestView::OnTouchEvent(ui::TouchEvent* event) { | 477 void TestView::OnTouchEvent(ui::TouchEvent* event) { |
| 478 last_touch_event_type_ = event->type(); | 478 last_touch_event_type_ = event->type(); |
| 479 location_.SetPoint(event->x(), event->y()); | 479 location_.SetPoint(event->x(), event->y()); |
| 480 if (!in_touch_sequence_) { | 480 if (!in_touch_sequence_) { |
| 481 if (event->type() == ui::ET_TOUCH_PRESSED) { | 481 if (event->type() == ui::ET_TOUCH_PRESSED) { |
| 482 in_touch_sequence_ = true; | 482 in_touch_sequence_ = true; |
| 483 return ui::ER_CONSUMED; | 483 event->StopPropagation(); |
| 484 return; |
| 484 } | 485 } |
| 485 } else { | 486 } else { |
| 486 if (event->type() == ui::ET_TOUCH_RELEASED) { | 487 if (event->type() == ui::ET_TOUCH_RELEASED) { |
| 487 in_touch_sequence_ = false; | 488 in_touch_sequence_ = false; |
| 488 return ui::ER_HANDLED; | 489 event->SetHandled(); |
| 490 return; |
| 489 } | 491 } |
| 490 return ui::ER_CONSUMED; | 492 event->StopPropagation(); |
| 493 return; |
| 491 } | 494 } |
| 492 return last_touch_event_was_handled_ ? ui::ER_CONSUMED : | 495 |
| 493 ui::ER_UNHANDLED; | 496 if (last_touch_event_was_handled_) |
| 497 event->StopPropagation(); |
| 494 } | 498 } |
| 495 | 499 |
| 496 ui::EventResult TestViewIgnoreTouch::OnTouchEvent(ui::TouchEvent* event) { | 500 void TestViewIgnoreTouch::OnTouchEvent(ui::TouchEvent* event) { |
| 497 return ui::ER_UNHANDLED; | |
| 498 } | 501 } |
| 499 | 502 |
| 500 TEST_F(ViewTest, TouchEvent) { | 503 TEST_F(ViewTest, TouchEvent) { |
| 501 TestView* v1 = new TestView(); | 504 TestView* v1 = new TestView(); |
| 502 v1->SetBoundsRect(gfx::Rect(0, 0, 300, 300)); | 505 v1->SetBoundsRect(gfx::Rect(0, 0, 300, 300)); |
| 503 | 506 |
| 504 TestView* v2 = new TestView(); | 507 TestView* v2 = new TestView(); |
| 505 v2->SetBoundsRect(gfx::Rect(100, 100, 100, 100)); | 508 v2->SetBoundsRect(gfx::Rect(100, 100, 100, 100)); |
| 506 | 509 |
| 507 TestView* v3 = new TestViewIgnoreTouch(); | 510 TestView* v3 = new TestViewIgnoreTouch(); |
| (...skipping 2893 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3401 // Set to non default value. | 3404 // Set to non default value. |
| 3402 v->layer()->set_scale_content(false); | 3405 v->layer()->set_scale_content(false); |
| 3403 scoped_ptr<ui::Layer> old_layer(v->RecreateLayer()); | 3406 scoped_ptr<ui::Layer> old_layer(v->RecreateLayer()); |
| 3404 ui::Layer* new_layer = v->layer(); | 3407 ui::Layer* new_layer = v->layer(); |
| 3405 EXPECT_FALSE(new_layer->scale_content()); | 3408 EXPECT_FALSE(new_layer->scale_content()); |
| 3406 } | 3409 } |
| 3407 | 3410 |
| 3408 #endif // USE_AURA | 3411 #endif // USE_AURA |
| 3409 | 3412 |
| 3410 } // namespace views | 3413 } // namespace views |
| OLD | NEW |