| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/chromeos/touch_exploration_controller.h" | 5 #include "ui/chromeos/touch_exploration_controller.h" |
| 6 | 6 |
| 7 #include <math.h> | 7 #include <math.h> |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 } | 178 } |
| 179 | 179 |
| 180 float GetSlopDistanceFromEdge() const { | 180 float GetSlopDistanceFromEdge() const { |
| 181 return touch_exploration_controller_->kSlopDistanceFromEdge; | 181 return touch_exploration_controller_->kSlopDistanceFromEdge; |
| 182 } | 182 } |
| 183 | 183 |
| 184 void SetTouchAccessibilityAnchorPoint(const gfx::Point& location) { | 184 void SetTouchAccessibilityAnchorPoint(const gfx::Point& location) { |
| 185 touch_exploration_controller_->SetTouchAccessibilityAnchorPoint(location); | 185 touch_exploration_controller_->SetTouchAccessibilityAnchorPoint(location); |
| 186 } | 186 } |
| 187 | 187 |
| 188 void SetExcludeBounds(const gfx::Rect& bounds) { |
| 189 touch_exploration_controller_->SetExcludeBounds(bounds); |
| 190 } |
| 191 |
| 188 private: | 192 private: |
| 189 std::unique_ptr<TouchExplorationController> touch_exploration_controller_; | 193 std::unique_ptr<TouchExplorationController> touch_exploration_controller_; |
| 190 | 194 |
| 191 DISALLOW_COPY_AND_ASSIGN(TouchExplorationControllerTestApi); | 195 DISALLOW_COPY_AND_ASSIGN(TouchExplorationControllerTestApi); |
| 192 }; | 196 }; |
| 193 | 197 |
| 194 class TouchExplorationTest : public aura::test::AuraTestBase { | 198 class TouchExplorationTest : public aura::test::AuraTestBase { |
| 195 public: | 199 public: |
| 196 TouchExplorationTest() : simulated_clock_(nullptr) {} | 200 TouchExplorationTest() : simulated_clock_(nullptr) {} |
| 197 ~TouchExplorationTest() override {} | 201 ~TouchExplorationTest() override {} |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 float GetSlopDistanceFromEdge() const { | 395 float GetSlopDistanceFromEdge() const { |
| 392 return touch_exploration_controller_->GetSlopDistanceFromEdge(); | 396 return touch_exploration_controller_->GetSlopDistanceFromEdge(); |
| 393 } | 397 } |
| 394 | 398 |
| 395 base::TimeTicks Now() { return ui::EventTimeForNow(); } | 399 base::TimeTicks Now() { return ui::EventTimeForNow(); } |
| 396 | 400 |
| 397 void SetTouchAccessibilityAnchorPoint(const gfx::Point& location) { | 401 void SetTouchAccessibilityAnchorPoint(const gfx::Point& location) { |
| 398 touch_exploration_controller_->SetTouchAccessibilityAnchorPoint(location); | 402 touch_exploration_controller_->SetTouchAccessibilityAnchorPoint(location); |
| 399 } | 403 } |
| 400 | 404 |
| 405 void SetExcludeBounds(const gfx::Rect& bounds) { |
| 406 touch_exploration_controller_->SetExcludeBounds(bounds); |
| 407 } |
| 408 |
| 401 std::unique_ptr<test::EventGenerator> generator_; | 409 std::unique_ptr<test::EventGenerator> generator_; |
| 402 ui::GestureDetector::Config gesture_detector_config_; | 410 ui::GestureDetector::Config gesture_detector_config_; |
| 403 // Owned by |ui|. | 411 // Owned by |ui|. |
| 404 base::SimpleTestTickClock* simulated_clock_; | 412 base::SimpleTestTickClock* simulated_clock_; |
| 405 MockTouchExplorationControllerDelegate delegate_; | 413 MockTouchExplorationControllerDelegate delegate_; |
| 406 | 414 |
| 407 private: | 415 private: |
| 408 EventCapturer event_capturer_; | 416 EventCapturer event_capturer_; |
| 409 std::unique_ptr<TouchExplorationControllerTestApi> | 417 std::unique_ptr<TouchExplorationControllerTestApi> |
| 410 touch_exploration_controller_; | 418 touch_exploration_controller_; |
| (...skipping 1434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1845 ++point) { | 1853 ++point) { |
| 1846 generator_->PressTouch(); | 1854 generator_->PressTouch(); |
| 1847 generator_->MoveTouch(initial_press); | 1855 generator_->MoveTouch(initial_press); |
| 1848 generator_->MoveTouch(*point); | 1856 generator_->MoveTouch(*point); |
| 1849 generator_->ReleaseTouch(); | 1857 generator_->ReleaseTouch(); |
| 1850 ASSERT_EQ(1U, delegate_.NumExitScreenSounds()); | 1858 ASSERT_EQ(1U, delegate_.NumExitScreenSounds()); |
| 1851 delegate_.ResetCountersToZero(); | 1859 delegate_.ResetCountersToZero(); |
| 1852 } | 1860 } |
| 1853 } | 1861 } |
| 1854 | 1862 |
| 1863 TEST_F(TouchExplorationTest, ExclusionArea) { |
| 1864 SwitchTouchExplorationMode(true); |
| 1865 |
| 1866 gfx::Rect window = BoundsOfRootWindowInDIP(); |
| 1867 gfx::Rect exclude = window; |
| 1868 exclude.Inset(0, 0, 0, 30); |
| 1869 SetExcludeBounds(exclude); |
| 1870 |
| 1871 gfx::Point in_pt = exclude.CenterPoint(); |
| 1872 gfx::Point in_mv_pt(in_pt.x(), (in_pt.y() + exclude.bottom()) / 2); |
| 1873 gfx::Point out_pt(in_pt.x(), exclude.bottom() + 20); |
| 1874 gfx::Point out_mv_pt(in_pt.x(), exclude.bottom() + 10); |
| 1875 |
| 1876 // Motion starting in exclusion bounds is passed-through unchanged. |
| 1877 { |
| 1878 generator_->set_current_location(in_pt); |
| 1879 generator_->PressTouchId(0); |
| 1880 AdvanceSimulatedTimePastPotentialTapDelay(); |
| 1881 generator_->MoveTouchId(out_mv_pt, 0); |
| 1882 generator_->ReleaseTouchId(0); |
| 1883 EXPECT_TRUE(IsInNoFingersDownState()); |
| 1884 const EventList& captured_events = GetCapturedEvents(); |
| 1885 ASSERT_EQ(3U, captured_events.size()); |
| 1886 EXPECT_EQ(ui::ET_TOUCH_PRESSED, captured_events[0]->type()); |
| 1887 EXPECT_EQ(ui::ET_TOUCH_MOVED, captured_events[1]->type()); |
| 1888 EXPECT_EQ(ui::ET_TOUCH_RELEASED, captured_events[2]->type()); |
| 1889 ClearCapturedEvents(); |
| 1890 } |
| 1891 |
| 1892 // Complete motion outside exclusion is rewritten. |
| 1893 { |
| 1894 generator_->set_current_location(out_pt); |
| 1895 generator_->PressTouchId(0); |
| 1896 AdvanceSimulatedTimePastTapDelay(); |
| 1897 generator_->MoveTouchId(out_mv_pt, 0); |
| 1898 generator_->ReleaseTouchId(0); |
| 1899 AdvanceSimulatedTimePastTapDelay(); |
| 1900 EXPECT_TRUE(IsInNoFingersDownState()); |
| 1901 const EventList& captured_events = GetCapturedEvents(); |
| 1902 ASSERT_EQ(3U, captured_events.size()); |
| 1903 for (const std::unique_ptr<ui::Event>& e : captured_events) { |
| 1904 EXPECT_EQ(ui::ET_MOUSE_MOVED, e->type()); |
| 1905 } |
| 1906 ClearCapturedEvents(); |
| 1907 } |
| 1908 |
| 1909 // For a motion starting outside: outside events are rewritten, inside |
| 1910 // events are discarded unless they end the motion. |
| 1911 { |
| 1912 // finger 0 down outside, moves inside. |
| 1913 generator_->set_current_location(out_pt); |
| 1914 generator_->PressTouchId(0); |
| 1915 AdvanceSimulatedTimePastTapDelay(); |
| 1916 generator_->MoveTouchId(out_mv_pt, 0); |
| 1917 generator_->MoveTouchId(in_mv_pt, 0); |
| 1918 ASSERT_EQ(2U, GetCapturedEvents().size()); |
| 1919 for (const std::unique_ptr<ui::Event>& e : GetCapturedEvents()) { |
| 1920 EXPECT_EQ(ui::ET_MOUSE_MOVED, e->type()); |
| 1921 } |
| 1922 ClearCapturedEvents(); |
| 1923 |
| 1924 // finger 1 down inside, moves outside |
| 1925 generator_->set_current_location(in_pt); |
| 1926 generator_->PressTouchId(1); |
| 1927 generator_->MoveTouchId(out_mv_pt, 1); |
| 1928 generator_->ReleaseTouchId(1); |
| 1929 ASSERT_EQ(0U, GetCapturedEvents().size()); |
| 1930 EXPECT_FALSE(IsInNoFingersDownState()); |
| 1931 |
| 1932 generator_->ReleaseTouchId(0); |
| 1933 AdvanceSimulatedTimePastTapDelay(); |
| 1934 EXPECT_TRUE(IsInNoFingersDownState()); |
| 1935 |
| 1936 ASSERT_EQ(1U, GetCapturedEvents().size()); |
| 1937 EXPECT_EQ(ui::ET_MOUSE_MOVED, GetCapturedEvents()[0]->type()); |
| 1938 ClearCapturedEvents(); |
| 1939 } |
| 1940 } |
| 1941 |
| 1855 } // namespace ui | 1942 } // namespace ui |
| OLD | NEW |