| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2016 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/env_input_state_controller.h" |
| 6 |
| 7 #include "ui/aura/client/screen_position_client.h" |
| 8 #include "ui/aura/env.h" |
| 9 #include "ui/events/event.h" |
| 10 #include "ui/gfx/geometry/point.h" |
| 11 |
| 12 namespace aura { |
| 13 |
| 14 void EnvInputStateController::UpdateStateForMouseEvent( |
| 15 const Window* window, |
| 16 const ui::MouseEvent& event) { |
| 17 switch (event.type()) { |
| 18 case ui::ET_MOUSE_PRESSED: |
| 19 Env::GetInstance()->set_mouse_button_flags(event.button_flags()); |
| 20 break; |
| 21 case ui::ET_MOUSE_RELEASED: |
| 22 Env::GetInstance()->set_mouse_button_flags( |
| 23 event.button_flags() & ~event.changed_button_flags()); |
| 24 break; |
| 25 default: |
| 26 break; |
| 27 } |
| 28 |
| 29 if (event.type() != ui::ET_MOUSE_CAPTURE_CHANGED && |
| 30 !(event.flags() & ui::EF_IS_SYNTHESIZED)) { |
| 31 SetLastMouseLocation(window, event.root_location()); |
| 32 } |
| 33 } |
| 34 |
| 35 void EnvInputStateController::UpdateStateForTouchEvent( |
| 36 const ui::TouchEvent& event) { |
| 37 switch (event.type()) { |
| 38 case ui::ET_TOUCH_PRESSED: |
| 39 touch_ids_down_ |= (1 << event.touch_id()); |
| 40 Env::GetInstance()->set_touch_down(touch_ids_down_ != 0); |
| 41 break; |
| 42 |
| 43 // Handle ET_TOUCH_CANCELLED only if it has a native event. |
| 44 case ui::ET_TOUCH_CANCELLED: |
| 45 if (!event.HasNativeEvent()) |
| 46 break; |
| 47 // fallthrough |
| 48 case ui::ET_TOUCH_RELEASED: |
| 49 touch_ids_down_ = |
| 50 (touch_ids_down_ | (1 << event.touch_id())) ^ (1 << event.touch_id()); |
| 51 Env::GetInstance()->set_touch_down(touch_ids_down_ != 0); |
| 52 break; |
| 53 |
| 54 case ui::ET_TOUCH_MOVED: |
| 55 break; |
| 56 |
| 57 default: |
| 58 NOTREACHED(); |
| 59 break; |
| 60 } |
| 61 } |
| 62 |
| 63 void EnvInputStateController::SetLastMouseLocation( |
| 64 const Window* root_window, |
| 65 const gfx::Point& location_in_root) const { |
| 66 client::ScreenPositionClient* client = |
| 67 client::GetScreenPositionClient(root_window); |
| 68 if (client) { |
| 69 gfx::Point location_in_screen = location_in_root; |
| 70 client->ConvertPointToScreen(root_window, &location_in_screen); |
| 71 Env::GetInstance()->set_last_mouse_location(location_in_screen); |
| 72 } else { |
| 73 Env::GetInstance()->set_last_mouse_location(location_in_root); |
| 74 } |
| 75 } |
| 76 |
| 77 } // namespace aura |
| OLD | NEW |