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 "base/macros.h" | 10 #include "base/macros.h" |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 } | 173 } |
174 | 174 |
175 float GetSlopDistanceFromEdge() const { | 175 float GetSlopDistanceFromEdge() const { |
176 return touch_exploration_controller_->kSlopDistanceFromEdge; | 176 return touch_exploration_controller_->kSlopDistanceFromEdge; |
177 } | 177 } |
178 | 178 |
179 void SetTouchAccessibilityAnchorPoint(const gfx::Point& location) { | 179 void SetTouchAccessibilityAnchorPoint(const gfx::Point& location) { |
180 touch_exploration_controller_->SetTouchAccessibilityAnchorPoint(location); | 180 touch_exploration_controller_->SetTouchAccessibilityAnchorPoint(location); |
181 } | 181 } |
182 | 182 |
| 183 void SetExcludeBounds(const gfx::Rect& bounds) { |
| 184 touch_exploration_controller_->SetExcludeBounds(bounds); |
| 185 } |
| 186 |
183 private: | 187 private: |
184 std::unique_ptr<TouchExplorationController> touch_exploration_controller_; | 188 std::unique_ptr<TouchExplorationController> touch_exploration_controller_; |
185 | 189 |
186 DISALLOW_COPY_AND_ASSIGN(TouchExplorationControllerTestApi); | 190 DISALLOW_COPY_AND_ASSIGN(TouchExplorationControllerTestApi); |
187 }; | 191 }; |
188 | 192 |
189 class TouchExplorationTest : public aura::test::AuraTestBase { | 193 class TouchExplorationTest : public aura::test::AuraTestBase { |
190 public: | 194 public: |
191 TouchExplorationTest() : simulated_clock_(nullptr) {} | 195 TouchExplorationTest() : simulated_clock_(nullptr) {} |
192 ~TouchExplorationTest() override {} | 196 ~TouchExplorationTest() override {} |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 float GetSlopDistanceFromEdge() const { | 389 float GetSlopDistanceFromEdge() const { |
386 return touch_exploration_controller_->GetSlopDistanceFromEdge(); | 390 return touch_exploration_controller_->GetSlopDistanceFromEdge(); |
387 } | 391 } |
388 | 392 |
389 base::TimeTicks Now() { return ui::EventTimeForNow(); } | 393 base::TimeTicks Now() { return ui::EventTimeForNow(); } |
390 | 394 |
391 void SetTouchAccessibilityAnchorPoint(const gfx::Point& location) { | 395 void SetTouchAccessibilityAnchorPoint(const gfx::Point& location) { |
392 touch_exploration_controller_->SetTouchAccessibilityAnchorPoint(location); | 396 touch_exploration_controller_->SetTouchAccessibilityAnchorPoint(location); |
393 } | 397 } |
394 | 398 |
| 399 void SetExcludeBounds(const gfx::Rect& bounds) { |
| 400 touch_exploration_controller_->SetExcludeBounds(bounds); |
| 401 } |
| 402 |
395 std::unique_ptr<test::EventGenerator> generator_; | 403 std::unique_ptr<test::EventGenerator> generator_; |
396 ui::GestureDetector::Config gesture_detector_config_; | 404 ui::GestureDetector::Config gesture_detector_config_; |
397 // Owned by |ui|. | 405 // Owned by |ui|. |
398 base::SimpleTestTickClock* simulated_clock_; | 406 base::SimpleTestTickClock* simulated_clock_; |
399 MockTouchExplorationControllerDelegate delegate_; | 407 MockTouchExplorationControllerDelegate delegate_; |
400 | 408 |
401 private: | 409 private: |
402 EventCapturer event_capturer_; | 410 EventCapturer event_capturer_; |
403 std::unique_ptr<TouchExplorationControllerTestApi> | 411 std::unique_ptr<TouchExplorationControllerTestApi> |
404 touch_exploration_controller_; | 412 touch_exploration_controller_; |
(...skipping 1407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1812 ++point) { | 1820 ++point) { |
1813 generator_->PressTouch(); | 1821 generator_->PressTouch(); |
1814 generator_->MoveTouch(initial_press); | 1822 generator_->MoveTouch(initial_press); |
1815 generator_->MoveTouch(*point); | 1823 generator_->MoveTouch(*point); |
1816 generator_->ReleaseTouch(); | 1824 generator_->ReleaseTouch(); |
1817 ASSERT_EQ(1U, delegate_.NumExitScreenSounds()); | 1825 ASSERT_EQ(1U, delegate_.NumExitScreenSounds()); |
1818 delegate_.ResetCountersToZero(); | 1826 delegate_.ResetCountersToZero(); |
1819 } | 1827 } |
1820 } | 1828 } |
1821 | 1829 |
| 1830 TEST_F(TouchExplorationTest, ExclusionArea) { |
| 1831 SwitchTouchExplorationMode(true); |
| 1832 |
| 1833 gfx::Rect window = BoundsOfRootWindowInDIP(); |
| 1834 gfx::Rect exclude = window; |
| 1835 exclude.Inset(0, 0, 0, 30); |
| 1836 SetExcludeBounds(exclude); |
| 1837 |
| 1838 gfx::Point in_pt = exclude.CenterPoint(); |
| 1839 gfx::Point in_mv_pt(in_pt.x(), (in_pt.y() + exclude.bottom()) / 2); |
| 1840 gfx::Point out_pt(in_pt.x(), exclude.bottom() + 20); |
| 1841 gfx::Point out_mv_pt(in_pt.x(), exclude.bottom() + 10); |
| 1842 |
| 1843 // Motion starting in exclusion bounds is passed-through unchanged. |
| 1844 { |
| 1845 generator_->set_current_location(in_pt); |
| 1846 generator_->PressTouchId(0); |
| 1847 AdvanceSimulatedTimePastPotentialTapDelay(); |
| 1848 generator_->MoveTouchId(out_mv_pt, 0); |
| 1849 generator_->ReleaseTouchId(0); |
| 1850 EXPECT_TRUE(IsInNoFingersDownState()); |
| 1851 const ScopedVector<ui::Event>& captured_events = GetCapturedEvents(); |
| 1852 ASSERT_EQ(3U, captured_events.size()); |
| 1853 EXPECT_EQ(ui::ET_TOUCH_PRESSED, captured_events[0]->type()); |
| 1854 EXPECT_EQ(ui::ET_TOUCH_MOVED, captured_events[1]->type()); |
| 1855 EXPECT_EQ(ui::ET_TOUCH_RELEASED, captured_events[2]->type()); |
| 1856 ClearCapturedEvents(); |
| 1857 } |
| 1858 |
| 1859 // Complete motion outside exclusion is rewritten. |
| 1860 { |
| 1861 generator_->set_current_location(out_pt); |
| 1862 generator_->PressTouchId(0); |
| 1863 AdvanceSimulatedTimePastTapDelay(); |
| 1864 generator_->MoveTouchId(out_mv_pt, 0); |
| 1865 generator_->ReleaseTouchId(0); |
| 1866 AdvanceSimulatedTimePastTapDelay(); |
| 1867 EXPECT_TRUE(IsInNoFingersDownState()); |
| 1868 const ScopedVector<ui::Event>& captured_events = GetCapturedEvents(); |
| 1869 ASSERT_EQ(3U, captured_events.size()); |
| 1870 for (ui::Event* e : captured_events) { |
| 1871 EXPECT_EQ(ui::ET_MOUSE_MOVED, e->type()); |
| 1872 } |
| 1873 ClearCapturedEvents(); |
| 1874 } |
| 1875 |
| 1876 // For a motion starting outside: outside events are rewritten, inside |
| 1877 // events are discarded unless they end the motion. |
| 1878 { |
| 1879 // finger 0 down outside, moves inside. |
| 1880 generator_->set_current_location(out_pt); |
| 1881 generator_->PressTouchId(0); |
| 1882 AdvanceSimulatedTimePastTapDelay(); |
| 1883 generator_->MoveTouchId(out_mv_pt, 0); |
| 1884 generator_->MoveTouchId(in_mv_pt, 0); |
| 1885 ASSERT_EQ(2U, GetCapturedEvents().size()); |
| 1886 for (ui::Event* e : GetCapturedEvents()) { |
| 1887 EXPECT_EQ(ui::ET_MOUSE_MOVED, e->type()); |
| 1888 } |
| 1889 ClearCapturedEvents(); |
| 1890 |
| 1891 // finger 1 down inside, moves outside |
| 1892 generator_->set_current_location(in_pt); |
| 1893 generator_->PressTouchId(1); |
| 1894 generator_->MoveTouchId(out_mv_pt, 1); |
| 1895 generator_->ReleaseTouchId(1); |
| 1896 ASSERT_EQ(0U, GetCapturedEvents().size()); |
| 1897 EXPECT_FALSE(IsInNoFingersDownState()); |
| 1898 |
| 1899 generator_->ReleaseTouchId(0); |
| 1900 AdvanceSimulatedTimePastTapDelay(); |
| 1901 EXPECT_TRUE(IsInNoFingersDownState()); |
| 1902 |
| 1903 ASSERT_EQ(1U, GetCapturedEvents().size()); |
| 1904 EXPECT_EQ(ui::ET_MOUSE_MOVED, GetCapturedEvents()[0]->type()); |
| 1905 ClearCapturedEvents(); |
| 1906 } |
| 1907 } |
| 1908 |
1822 } // namespace ui | 1909 } // namespace ui |
OLD | NEW |