| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "ui/aura/mus/hit_test_data_provider_mus.h" |
| 6 |
| 7 #include "base/containers/adapters.h" |
| 8 #include "ui/aura/mus/window_port_mus.h" |
| 9 #include "ui/aura/window.h" |
| 10 #include "ui/aura/window_targeter.h" |
| 11 |
| 12 namespace aura { |
| 13 |
| 14 HitTestDataProviderMus::HitTestDataProviderMus(aura::Window* window) |
| 15 : window_(window) {} |
| 16 |
| 17 HitTestDataProviderMus::~HitTestDataProviderMus() {} |
| 18 |
| 19 std::unique_ptr<viz::HitTestDataProvider::HitTestRegionList> |
| 20 HitTestDataProviderMus::GetHitTestData() { |
| 21 auto hit_test_region_list = base::MakeUnique<HitTestRegionList>(); |
| 22 GetHitTestDataRecursively(window_, hit_test_region_list.get()); |
| 23 return hit_test_region_list; |
| 24 } |
| 25 |
| 26 void HitTestDataProviderMus::GetHitTestDataRecursively( |
| 27 aura::Window* window, |
| 28 HitTestRegionList* hit_test_region_list) { |
| 29 WindowTargeter* targeter = |
| 30 static_cast<WindowTargeter*>(window->GetEventTargeter()); |
| 31 |
| 32 // Walk the children in Z-order (reversed order of children()) to produce |
| 33 // the hit-test data. Each child's hit test data is added before the hit-test |
| 34 // data from the child's descendants because the child could clip its |
| 35 // descendants for the purpose of event handling. |
| 36 for (aura::Window* child : base::Reversed(window->children())) { |
| 37 gfx::Rect rect_mouse; |
| 38 gfx::Rect rect_touch; |
| 39 if (targeter && |
| 40 targeter->GetHitTestRects(child, &rect_mouse, &rect_touch)) { |
| 41 const bool touch_and_mouse_are_same = rect_mouse == rect_touch; |
| 42 const WindowPortMus* window_port = WindowPortMus::Get(child); |
| 43 viz::DisplayHitTestRegion hit_test_region = {window_port->frame_sink_id(), |
| 44 window_port->server_id(), 0}; |
| 45 if (!rect_mouse.IsEmpty()) { |
| 46 hit_test_region.flags = touch_and_mouse_are_same ? 0x03 : 0x01; |
| 47 hit_test_region.rect = rect_mouse; |
| 48 hit_test_region_list->push_back(hit_test_region); |
| 49 } |
| 50 if (!touch_and_mouse_are_same && !rect_touch.IsEmpty()) { |
| 51 hit_test_region.flags = 0x02; |
| 52 hit_test_region.rect = rect_touch; |
| 53 hit_test_region_list->push_back(hit_test_region); |
| 54 } |
| 55 } |
| 56 GetHitTestDataRecursively(child, hit_test_region_list); |
| 57 } |
| 58 } |
| 59 |
| 60 } // namespace aura |
| OLD | NEW |