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

Side by Side Diff: ui/views/view_unittest.cc

Issue 10912063: events: Get rid of GestureStatus in favour of EventResult. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « ui/views/view.cc ('k') | ui/views/widget/native_widget_aura.h » ('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 (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
225 } 225 }
226 226
227 virtual void OnBoundsChanged(const gfx::Rect& previous_bounds) OVERRIDE; 227 virtual void OnBoundsChanged(const gfx::Rect& previous_bounds) OVERRIDE;
228 virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE; 228 virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE;
229 virtual bool OnMouseDragged(const ui::MouseEvent& event) OVERRIDE; 229 virtual bool OnMouseDragged(const ui::MouseEvent& event) OVERRIDE;
230 virtual void OnMouseReleased(const ui::MouseEvent& event) OVERRIDE; 230 virtual void OnMouseReleased(const ui::MouseEvent& event) OVERRIDE;
231 virtual void OnMouseEntered(const ui::MouseEvent& event) OVERRIDE; 231 virtual void OnMouseEntered(const ui::MouseEvent& event) OVERRIDE;
232 virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE; 232 virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE;
233 virtual ui::TouchStatus OnTouchEvent(const ui::TouchEvent& event) OVERRIDE; 233 virtual ui::TouchStatus OnTouchEvent(const ui::TouchEvent& event) OVERRIDE;
234 // Ignores GestureEvent by default. 234 // Ignores GestureEvent by default.
235 virtual ui::GestureStatus OnGestureEvent( 235 virtual ui::EventResult OnGestureEvent(
236 const ui::GestureEvent& event) OVERRIDE; 236 const ui::GestureEvent& event) OVERRIDE;
237 virtual void Paint(gfx::Canvas* canvas) OVERRIDE; 237 virtual void Paint(gfx::Canvas* canvas) OVERRIDE;
238 virtual void SchedulePaintInRect(const gfx::Rect& rect) OVERRIDE; 238 virtual void SchedulePaintInRect(const gfx::Rect& rect) OVERRIDE;
239 virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE; 239 virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE;
240 240
241 // OnBoundsChanged. 241 // OnBoundsChanged.
242 bool did_change_bounds_; 242 bool did_change_bounds_;
243 gfx::Rect new_bounds_; 243 gfx::Rect new_bounds_;
244 244
245 // MouseEvent. 245 // MouseEvent.
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 virtual ui::TouchStatus OnTouchEvent(const ui::TouchEvent& event) OVERRIDE; 278 virtual ui::TouchStatus OnTouchEvent(const ui::TouchEvent& event) OVERRIDE;
279 }; 279 };
280 280
281 // A view subclass that consumes all Gesture events for testing purposes. 281 // A view subclass that consumes all Gesture events for testing purposes.
282 class TestViewConsumeGesture : public TestView { 282 class TestViewConsumeGesture : public TestView {
283 public: 283 public:
284 TestViewConsumeGesture() : TestView() {} 284 TestViewConsumeGesture() : TestView() {}
285 virtual ~TestViewConsumeGesture() {} 285 virtual ~TestViewConsumeGesture() {}
286 286
287 protected: 287 protected:
288 virtual ui::GestureStatus OnGestureEvent( 288 virtual ui::EventResult OnGestureEvent(
289 const ui::GestureEvent& event) OVERRIDE { 289 const ui::GestureEvent& event) OVERRIDE {
290 last_gesture_event_type_ = event.type(); 290 last_gesture_event_type_ = event.type();
291 location_.SetPoint(event.x(), event.y()); 291 location_.SetPoint(event.x(), event.y());
292 return ui::GESTURE_STATUS_CONSUMED; 292 return ui::ER_CONSUMED;
293 } 293 }
294 294
295 private: 295 private:
296 DISALLOW_COPY_AND_ASSIGN(TestViewConsumeGesture); 296 DISALLOW_COPY_AND_ASSIGN(TestViewConsumeGesture);
297 }; 297 };
298 298
299 // A view subclass that ignores all Gesture events. 299 // A view subclass that ignores all Gesture events.
300 class TestViewIgnoreGesture: public TestView { 300 class TestViewIgnoreGesture: public TestView {
301 public: 301 public:
302 TestViewIgnoreGesture() : TestView() {} 302 TestViewIgnoreGesture() : TestView() {}
303 virtual ~TestViewIgnoreGesture() {} 303 virtual ~TestViewIgnoreGesture() {}
304 304
305 private: 305 private:
306 virtual ui::GestureStatus OnGestureEvent( 306 virtual ui::EventResult OnGestureEvent(
307 const ui::GestureEvent& event) OVERRIDE { 307 const ui::GestureEvent& event) OVERRIDE {
308 return ui::GESTURE_STATUS_UNKNOWN; 308 return ui::ER_UNHANDLED;
309 } 309 }
310 310
311 DISALLOW_COPY_AND_ASSIGN(TestViewIgnoreGesture); 311 DISALLOW_COPY_AND_ASSIGN(TestViewIgnoreGesture);
312 }; 312 };
313 313
314 // A view subclass that ignores all scroll-gesture events, but consume all other 314 // A view subclass that ignores all scroll-gesture events, but consume all other
315 // gesture events. 315 // gesture events.
316 class TestViewIgnoreScrollGestures : public TestViewConsumeGesture { 316 class TestViewIgnoreScrollGestures : public TestViewConsumeGesture {
317 public: 317 public:
318 TestViewIgnoreScrollGestures() {} 318 TestViewIgnoreScrollGestures() {}
319 virtual ~TestViewIgnoreScrollGestures() {} 319 virtual ~TestViewIgnoreScrollGestures() {}
320 320
321 private: 321 private:
322 virtual ui::GestureStatus OnGestureEvent( 322 virtual ui::EventResult OnGestureEvent(
323 const ui::GestureEvent& event) OVERRIDE { 323 const ui::GestureEvent& event) OVERRIDE {
324 if (event.IsScrollGestureEvent()) 324 if (event.IsScrollGestureEvent())
325 return ui::GESTURE_STATUS_UNKNOWN; 325 return ui::ER_UNHANDLED;
326 return TestViewConsumeGesture::OnGestureEvent(event); 326 return TestViewConsumeGesture::OnGestureEvent(event);
327 } 327 }
328 328
329 DISALLOW_COPY_AND_ASSIGN(TestViewIgnoreScrollGestures); 329 DISALLOW_COPY_AND_ASSIGN(TestViewIgnoreScrollGestures);
330 }; 330 };
331 331
332 //////////////////////////////////////////////////////////////////////////////// 332 ////////////////////////////////////////////////////////////////////////////////
333 // OnBoundsChanged 333 // OnBoundsChanged
334 //////////////////////////////////////////////////////////////////////////////// 334 ////////////////////////////////////////////////////////////////////////////////
335 335
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
582 root->OnTouchEvent(released); 582 root->OnTouchEvent(released);
583 EXPECT_EQ(v2->last_touch_event_type_, ui::ET_TOUCH_RELEASED); 583 EXPECT_EQ(v2->last_touch_event_type_, ui::ET_TOUCH_RELEASED);
584 EXPECT_EQ(v2->location_.x(), -100); 584 EXPECT_EQ(v2->location_.x(), -100);
585 EXPECT_EQ(v2->location_.y(), -100); 585 EXPECT_EQ(v2->location_.y(), -100);
586 // Make sure v1 did not receive the event 586 // Make sure v1 did not receive the event
587 EXPECT_EQ(v1->last_touch_event_type_, 0); 587 EXPECT_EQ(v1->last_touch_event_type_, 0);
588 588
589 widget->CloseNow(); 589 widget->CloseNow();
590 } 590 }
591 591
592 ui::GestureStatus TestView::OnGestureEvent(const ui::GestureEvent& event) { 592 ui::EventResult TestView::OnGestureEvent(const ui::GestureEvent& event) {
593 return ui::GESTURE_STATUS_UNKNOWN; 593 return ui::ER_UNHANDLED;
594 } 594 }
595 595
596 TEST_F(ViewTest, GestureEvent) { 596 TEST_F(ViewTest, GestureEvent) {
597 // Views hierarchy for non delivery of GestureEvent. 597 // Views hierarchy for non delivery of GestureEvent.
598 TestView* v1 = new TestViewConsumeGesture(); 598 TestView* v1 = new TestViewConsumeGesture();
599 v1->SetBoundsRect(gfx::Rect(0, 0, 300, 300)); 599 v1->SetBoundsRect(gfx::Rect(0, 0, 300, 300));
600 600
601 TestView* v2 = new TestViewConsumeGesture(); 601 TestView* v2 = new TestViewConsumeGesture();
602 v2->SetBoundsRect(gfx::Rect(100, 100, 100, 100)); 602 v2->SetBoundsRect(gfx::Rect(100, 100, 100, 100));
603 603
(...skipping 2778 matching lines...) Expand 10 before | Expand all | Expand 10 after
3382 // Set to non default value. 3382 // Set to non default value.
3383 v->layer()->set_scale_content(false); 3383 v->layer()->set_scale_content(false);
3384 scoped_ptr<ui::Layer> old_layer(v->RecreateLayer()); 3384 scoped_ptr<ui::Layer> old_layer(v->RecreateLayer());
3385 ui::Layer* new_layer = v->layer(); 3385 ui::Layer* new_layer = v->layer();
3386 EXPECT_FALSE(new_layer->scale_content()); 3386 EXPECT_FALSE(new_layer->scale_content());
3387 } 3387 }
3388 3388
3389 #endif // USE_AURA 3389 #endif // USE_AURA
3390 3390
3391 } // namespace views 3391 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/view.cc ('k') | ui/views/widget/native_widget_aura.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698