1a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// Copyright 2014 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "ui/aura/window_event_dispatcher.h" 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/bind.h" 85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/debug/trace_event.h" 95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/logging.h" 10ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch#include "base/message_loop/message_loop.h" 115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/aura/client/capture_client.h" 125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/aura/client/cursor_client.h" 135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/aura/client/event_client.h" 142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/aura/client/focus_client.h" 155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/aura/client/screen_position_client.h" 165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/aura/env.h" 175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/aura/window.h" 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/aura/window_delegate.h" 19a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "ui/aura/window_targeter.h" 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/aura/window_tracker.h" 21f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "ui/aura/window_tree_host.h" 225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/base/hit_test.h" 235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/compositor/dip_util.h" 24d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#include "ui/events/event.h" 2568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)#include "ui/events/gestures/gesture_recognizer.h" 2668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)#include "ui/events/gestures/gesture_types.h" 275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 28f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)typedef ui::EventDispatchDetails DispatchDetails; 29f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace aura { 315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace { 335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Returns true if |target| has a non-client (frame) component at |location|, 355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// in window coordinates. 365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool IsNonClientLocation(Window* target, const gfx::Point& location) { 375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (!target->delegate()) 385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return false; 395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int hit_test_code = target->delegate()->GetNonClientComponent(location); 405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return hit_test_code != HTCLIENT && hit_test_code != HTNOWHERE; 415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)Window* ConsumerToWindow(ui::GestureConsumer* consumer) { 448bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) return consumer ? static_cast<Window*>(consumer) : NULL; 455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 47f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)void SetLastMouseLocation(const Window* root_window, 482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const gfx::Point& location_in_root) { 492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) client::ScreenPositionClient* client = 502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) client::GetScreenPositionClient(root_window); 512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (client) { 522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gfx::Point location_in_screen = location_in_root; 532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) client->ConvertPointToScreen(root_window, &location_in_screen); 542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Env::GetInstance()->set_last_mouse_location(location_in_screen); 552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } else { 562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Env::GetInstance()->set_last_mouse_location(location_in_root); 572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool IsEventCandidateForHold(const ui::Event& event) { 615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (event.type() == ui::ET_TOUCH_MOVED) 625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return true; 635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (event.type() == ui::ET_MOUSE_DRAGGED) 645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return true; 655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (event.IsMouseEvent() && (event.flags() & ui::EF_IS_SYNTHESIZED)) 665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return true; 675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return false; 685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 69c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace 715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//////////////////////////////////////////////////////////////////////////////// 73a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// WindowEventDispatcher, public: 745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 75a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)WindowEventDispatcher::WindowEventDispatcher(WindowTreeHost* host) 76a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) : host_(host), 775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) touch_ids_down_(0), 785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) mouse_pressed_handler_(NULL), 795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) mouse_moved_handler_(NULL), 805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) event_dispatch_target_(NULL), 81a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) old_dispatch_target_(NULL), 825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) synthesize_mouse_move_(false), 837d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) move_hold_count_(0), 845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) dispatching_held_event_(false), 85effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch observer_manager_(this), 86f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) repost_event_factory_(this), 870f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) held_event_factory_(this) { 888bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) ui::GestureRecognizer::Get()->AddGestureEventHelper(this); 89effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch Env::GetInstance()->AddObserver(this); 905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 92a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)WindowEventDispatcher::~WindowEventDispatcher() { 93a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) TRACE_EVENT0("shutdown", "WindowEventDispatcher::Destructor"); 94effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch Env::GetInstance()->RemoveObserver(this); 958bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) ui::GestureRecognizer::Get()->RemoveGestureEventHelper(this); 965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 98a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void WindowEventDispatcher::RepostEvent(const ui::LocatedEvent& event) { 993551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) DCHECK(event.type() == ui::ET_MOUSE_PRESSED || 1003551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) event.type() == ui::ET_GESTURE_TAP_DOWN); 1012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // We allow for only one outstanding repostable event. This is used 1022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // in exiting context menus. A dropped repost request is allowed. 1032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (event.type() == ui::ET_MOUSE_PRESSED) { 1042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) held_repostable_event_.reset( 1052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) new ui::MouseEvent( 1062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) static_cast<const ui::MouseEvent&>(event), 1072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) static_cast<aura::Window*>(event.target()), 108f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) window())); 1095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::MessageLoop::current()->PostNonNestableTask( 110a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) FROM_HERE, base::Bind( 111a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) base::IgnoreResult(&WindowEventDispatcher::DispatchHeldEvents), 112a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) repost_event_factory_.GetWeakPtr())); 1132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } else { 1141e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) DCHECK(event.type() == ui::ET_GESTURE_TAP_DOWN); 1151e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) held_repostable_event_.reset(); 1161e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // TODO(rbyers): Reposing of gestures is tricky to get 1171e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // right, so it's not yet supported. crbug.com/170987. 1182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 1192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 1202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 121a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void WindowEventDispatcher::OnMouseEventsEnableStateChanged(bool enabled) { 1225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Send entered / exited so that visual state can be updated to match 1232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // mouse events state. 1245c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu PostSynthesizeMouseMove(); 1252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // TODO(mazda): Add code to disable mouse events when |enabled| == false. 1265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 128a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void WindowEventDispatcher::DispatchCancelModeEvent() { 129a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) ui::CancelModeEvent event; 130a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) Window* focused_window = client::GetFocusClient(window())->GetFocusedWindow(); 131a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) if (focused_window && !window()->Contains(focused_window)) 132a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) focused_window = NULL; 133a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) DispatchDetails details = 134a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) DispatchEvent(focused_window ? focused_window : window(), &event); 135a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) if (details.dispatcher_destroyed) 136a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) return; 137a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)} 138a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 139a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void WindowEventDispatcher::DispatchGestureEvent(ui::GestureEvent* event) { 140f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) DispatchDetails details = DispatchHeldEvents(); 141f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) if (details.dispatcher_destroyed) 142f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) return; 1432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Window* target = GetGestureTarget(event); 1445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (target) { 145f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) event->ConvertLocationToTarget(window(), target); 146a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) DispatchDetails details = DispatchEvent(target, event); 147f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) if (details.dispatcher_destroyed) 148f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) return; 1495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 152116680a4aac90f2aa7413d9095a592090648e557Ben MurdochDispatchDetails WindowEventDispatcher::DispatchMouseExitAtPoint( 153116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch const gfx::Point& point) { 1545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ui::MouseEvent event(ui::ET_MOUSE_EXITED, point, point, ui::EF_NONE, 1555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ui::EF_NONE); 156116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch return DispatchMouseEnterOrExit(event, ui::ET_MOUSE_EXITED); 15790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)} 15890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 159a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void WindowEventDispatcher::ProcessedTouchEvent(ui::TouchEvent* event, 160a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) Window* window, 161a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) ui::EventResult result) { 1621320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci // TODO(tdresser): Move this to PreDispatchTouchEvent, to enable eager 1631320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci // gesture detection. See crbug.com/410280. 1641320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci if (!ui::GestureRecognizer::Get() 1651320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci ->ProcessTouchEventPreDispatch(*event, window)) { 1661320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci return; 1671320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci } 1681320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 1696e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) // Once we've fully migrated to the eager gesture detector, we won't need to 1706e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) // pass an event here. 1716e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) scoped_ptr<ui::GestureRecognizer::Gestures> gestures( 1726e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) ui::GestureRecognizer::Get()->ProcessTouchEventOnAsyncAck( 1731320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci *event, result, window)); 174f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) DispatchDetails details = ProcessGestures(gestures.get()); 175f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) if (details.dispatcher_destroyed) 176f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) return; 1775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 179a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void WindowEventDispatcher::HoldPointerMoves() { 1807d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) if (!move_hold_count_) 1812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) held_event_factory_.InvalidateWeakPtrs(); 1827d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) ++move_hold_count_; 183a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) TRACE_EVENT_ASYNC_BEGIN0("ui", "WindowEventDispatcher::HoldPointerMoves", 184a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) this); 1857d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)} 1867d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 187a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void WindowEventDispatcher::ReleasePointerMoves() { 1887d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) --move_hold_count_; 1897d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) DCHECK_GE(move_hold_count_, 0); 1907d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) if (!move_hold_count_ && held_move_event_) { 1917d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // We don't want to call DispatchHeldEvents directly, because this might be 1927d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // called from a deep stack while another event, in which case dispatching 1937d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // another one may not be safe/expected. Instead we post a task, that we 1947d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // may cancel if HoldPointerMoves is called again before it executes. 1955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::MessageLoop::current()->PostNonNestableTask( 196a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) FROM_HERE, base::Bind( 197a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) base::IgnoreResult(&WindowEventDispatcher::DispatchHeldEvents), 198a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) held_event_factory_.GetWeakPtr())); 1995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 200a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) TRACE_EVENT_ASYNC_END0("ui", "WindowEventDispatcher::HoldPointerMoves", this); 2015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 203a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)gfx::Point WindowEventDispatcher::GetLastMouseLocationInRoot() const { 2045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Point location = Env::GetInstance()->last_mouse_location(); 205f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) client::ScreenPositionClient* client = 206f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) client::GetScreenPositionClient(window()); 2075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (client) 208f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) client->ConvertPointFromScreen(window(), &location); 2095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return location; 2105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2125f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)void WindowEventDispatcher::OnHostLostMouseGrab() { 2135f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) mouse_pressed_handler_ = NULL; 2145f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) mouse_moved_handler_ = NULL; 2155f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)} 2165f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 217a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void WindowEventDispatcher::OnCursorMovedToRootLocation( 218a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) const gfx::Point& root_location) { 219a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) SetLastMouseLocation(window(), root_location); 220a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) synthesize_mouse_move_ = false; 221a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)} 222a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 223effb81e5f8246d0db0270817048dc992db66e9fbBen Murdochvoid WindowEventDispatcher::OnPostNotifiedWindowDestroying(Window* window) { 224effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch OnWindowHidden(window, WINDOW_DESTROYED); 225effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch} 226effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 2275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//////////////////////////////////////////////////////////////////////////////// 228a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// WindowEventDispatcher, private: 2295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 23023730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)Window* WindowEventDispatcher::window() { 23123730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) return host_->window(); 23223730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)} 23323730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) 23423730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)const Window* WindowEventDispatcher::window() const { 23523730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) return host_->window(); 23623730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)} 23723730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) 238a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void WindowEventDispatcher::TransformEventForDeviceScaleFactor( 239a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) ui::LocatedEvent* event) { 24023730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) event->UpdateForRootTransform(host_->GetInverseRootTransform()); 2412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 2422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 243effb81e5f8246d0db0270817048dc992db66e9fbBen Murdochvoid WindowEventDispatcher::DispatchMouseExitToHidingWindow(Window* window) { 244effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch // The mouse capture is intentionally ignored. Think that a mouse enters 245effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch // to a window, the window sets the capture, the mouse exits the window, 246effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch // and then it releases the capture. In that case OnMouseExited won't 247effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch // be called. So it is natural not to emit OnMouseExited even though 248effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch // |window| is the capture window. 249effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch gfx::Point last_mouse_location = GetLastMouseLocationInRoot(); 250effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch if (window->Contains(mouse_moved_handler_) && 251116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch window->ContainsPointInRoot(last_mouse_location)) { 252116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch DispatchDetails details = DispatchMouseExitAtPoint(last_mouse_location); 253116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch if (details.dispatcher_destroyed) 254116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch return; 255116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch } 256effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch} 257effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 258a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)ui::EventDispatchDetails WindowEventDispatcher::DispatchMouseEnterOrExit( 259f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) const ui::MouseEvent& event, 260f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) ui::EventType type) { 2615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (event.type() != ui::ET_MOUSE_CAPTURE_CHANGED && 2625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) !(event.flags() & ui::EF_IS_SYNTHESIZED)) { 2635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) SetLastMouseLocation(window(), event.root_location()); 2645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 2655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 26623730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) if (!mouse_moved_handler_ || !mouse_moved_handler_->delegate() || 26723730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) !window()->Contains(mouse_moved_handler_)) 268f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) return DispatchDetails(); 2695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // |event| may be an event in the process of being dispatched to a target (in 2715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // which case its locations will be in the event's target's coordinate 2725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // system), or a synthetic event created in root-window (in which case, the 2735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // event's target will be NULL, and the event will be in the root-window's 2745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // coordinate system. 2755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) aura::Window* target = static_cast<Window*>(event.target()); 2765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (!target) 2775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) target = window(); 2782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ui::MouseEvent translated_event(event, 2795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) target, 2802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) mouse_moved_handler_, 2812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) type, 282eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch event.flags() | ui::EF_IS_SYNTHESIZED); 283a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) return DispatchEvent(mouse_moved_handler_, &translated_event); 2845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 286a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)ui::EventDispatchDetails WindowEventDispatcher::ProcessGestures( 287f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) ui::GestureRecognizer::Gestures* gestures) { 288f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) DispatchDetails details; 2892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (!gestures || gestures->empty()) 290f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) return details; 2912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Window* target = GetGestureTarget(gestures->get().at(0)); 2936e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) if (!target) 2946e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) return details; 2956e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) 2962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) for (size_t i = 0; i < gestures->size(); ++i) { 2972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ui::GestureEvent* event = gestures->get().at(i); 298f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) event->ConvertLocationToTarget(window(), target); 299a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) details = DispatchEvent(target, event); 300f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) if (details.dispatcher_destroyed || details.target_destroyed) 3012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) break; 3025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 303f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) return details; 3045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 3055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 306a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void WindowEventDispatcher::OnWindowHidden(Window* invisible, 307a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) WindowHiddenReason reason) { 3085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // If the window the mouse was pressed in becomes invisible, it should no 3095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // longer receive mouse events. 3105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (invisible->Contains(mouse_pressed_handler_)) 3115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) mouse_pressed_handler_ = NULL; 3125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (invisible->Contains(mouse_moved_handler_)) 3135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) mouse_moved_handler_ = NULL; 3145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 315a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // If events are being dispatched from a nested message-loop, and the target 316a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // of the outer loop is hidden or moved to another dispatcher during 317a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // dispatching events in the inner loop, then reset the target for the outer 318a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // loop. 319a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) if (invisible->Contains(old_dispatch_target_)) 320a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) old_dispatch_target_ = NULL; 321a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 322c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch invisible->CleanupGestureState(); 3235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 3242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Do not clear the capture, and the |event_dispatch_target_| if the 325effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch // window is moving across hosts, because the target itself is actually still 326effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch // visible and clearing them stops further event processing, which can cause 327effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch // unexpected behaviors. See crbug.com/157583 3285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (reason != WINDOW_MOVING) { 329effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch // We don't ask |invisible| here, because invisible may have been removed 330effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch // from the window hierarchy already by the time this function is called 331effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch // (OnWindowDestroyed). 332effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch client::CaptureClient* capture_client = 333effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch client::GetCaptureClient(host_->window()); 334effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch Window* capture_window = 335effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch capture_client ? capture_client->GetCaptureWindow() : NULL; 3365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (invisible->Contains(event_dispatch_target_)) 3385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) event_dispatch_target_ = NULL; 3395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // If the ancestor of the capture window is hidden, release the capture. 3415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Note that this may delete the window so do not use capture_window 3425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // after this. 3435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (invisible->Contains(capture_window) && invisible != window()) 3445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) capture_window->ReleaseCapture(); 3455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 3465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 3475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 348effb81e5f8246d0db0270817048dc992db66e9fbBen MurdochWindow* WindowEventDispatcher::GetGestureTarget(ui::GestureEvent* event) { 349effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch Window* target = NULL; 350effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch if (!event->IsEndingEvent()) { 351effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch // The window that received the start event (e.g. scroll begin) needs to 352effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch // receive the end event (e.g. scroll end). 353effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch target = client::GetCaptureWindow(window()); 354effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch } 355effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch if (!target) { 356effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch target = ConsumerToWindow( 357effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch ui::GestureRecognizer::Get()->GetTargetForGestureEvent(*event)); 358effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch } 359effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 360effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch return target; 361effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch} 362effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 3638bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)//////////////////////////////////////////////////////////////////////////////// 364a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// WindowEventDispatcher, aura::client::CaptureDelegate implementation: 3658bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 366a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void WindowEventDispatcher::UpdateCapture(Window* old_capture, 367a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) Window* new_capture) { 3688bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // |mouse_moved_handler_| may have been set to a Window in a different root 3698bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // (see below). Clear it here to ensure we don't end up referencing a stale 3708bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // Window. 371f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) if (mouse_moved_handler_ && !window()->Contains(mouse_moved_handler_)) 3728bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) mouse_moved_handler_ = NULL; 3738bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 374f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) if (old_capture && old_capture->GetRootWindow() == window() && 3758bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) old_capture->delegate()) { 3768bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // Send a capture changed event with bogus location data. 3778bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) ui::MouseEvent event(ui::ET_MOUSE_CAPTURE_CHANGED, gfx::Point(), 3785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) gfx::Point(), 0, 0); 3798bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 380a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) DispatchDetails details = DispatchEvent(old_capture, &event); 381f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) if (details.dispatcher_destroyed) 382f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) return; 3838bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 3848bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) old_capture->delegate()->OnCaptureLost(); 3858bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) } 3868bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 3878bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) if (new_capture) { 3888bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // Make all subsequent mouse events go to the capture window. We shouldn't 3898bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // need to send an event here as OnCaptureLost() should take care of that. 3908bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) if (mouse_moved_handler_ || Env::GetInstance()->IsMouseButtonDown()) 3918bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) mouse_moved_handler_ = new_capture; 3928bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) } else { 3938bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // Make sure mouse_moved_handler gets updated. 3945c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu DispatchDetails details = SynthesizeMouseMoveEvent(); 395f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) if (details.dispatcher_destroyed) 396f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) return; 3978bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) } 3988bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) mouse_pressed_handler_ = NULL; 3998bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)} 4008bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 401a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void WindowEventDispatcher::OnOtherRootGotCapture() { 4026e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) // Windows provides the TrackMouseEvents API which allows us to rely on the 4036e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) // OS to send us the mouse exit events (WM_MOUSELEAVE). Additionally on 4046e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) // desktop Windows, every top level window could potentially have its own 4056e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) // root window, in which case this function will get called whenever those 4066e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) // windows grab mouse capture. Sending mouse exit messages in these cases 4076e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) // causes subtle bugs like (crbug.com/394672). 4085f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#if !defined(OS_WIN) 409116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch if (mouse_moved_handler_) { 410116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // Dispatch a mouse exit to reset any state associated with hover. This is 411116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // important when going from no window having capture to a window having 412116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // capture because we do not dispatch ET_MOUSE_CAPTURE_CHANGED in this case. 413116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch DispatchDetails details = DispatchMouseExitAtPoint( 414116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch GetLastMouseLocationInRoot()); 415116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch if (details.dispatcher_destroyed) 416116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch return; 417116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch } 4185f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#endif 419116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 4201e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) mouse_moved_handler_ = NULL; 4211e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) mouse_pressed_handler_ = NULL; 4221e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} 4231e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 424a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void WindowEventDispatcher::SetNativeCapture() { 4258bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) host_->SetCapture(); 4268bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)} 4278bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 428a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void WindowEventDispatcher::ReleaseNativeCapture() { 4298bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) host_->ReleaseCapture(); 4308bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)} 4318bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 4328bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)//////////////////////////////////////////////////////////////////////////////// 433a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// WindowEventDispatcher, ui::EventProcessor implementation: 434a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)ui::EventTarget* WindowEventDispatcher::GetRootTarget() { 435a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) return window(); 436a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)} 437a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 438a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void WindowEventDispatcher::PrepareEventForDispatch(ui::Event* event) { 4395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (dispatching_held_event_) { 4405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // The held events are already in |window()|'s coordinate system. So it is 4415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // not necessary to apply the transform to convert from the host's 4425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // coordinate system to |window()|'s coordinate system. 4435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return; 4445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 4451320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci if (event->IsLocatedEvent()) { 4465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) TransformEventForDeviceScaleFactor(static_cast<ui::LocatedEvent*>(event)); 4475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 4485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 4495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 450a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)//////////////////////////////////////////////////////////////////////////////// 451a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// WindowEventDispatcher, ui::EventDispatcherDelegate implementation: 4528bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 453a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)bool WindowEventDispatcher::CanDispatchToTarget(ui::EventTarget* target) { 4545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return event_dispatch_target_ == target; 4555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 4565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 457a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)ui::EventDispatchDetails WindowEventDispatcher::PreDispatchEvent( 458a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) ui::EventTarget* target, 459a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) ui::Event* event) { 460a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) Window* target_window = static_cast<Window*>(target); 461a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) CHECK(window()->Contains(target_window)); 462a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 4635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (!dispatching_held_event_) { 4645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) bool can_be_held = IsEventCandidateForHold(*event); 4655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (!move_hold_count_ || !can_be_held) { 4665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (can_be_held) 4675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) held_move_event_.reset(); 4685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) DispatchDetails details = DispatchHeldEvents(); 4695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (details.dispatcher_destroyed || details.target_destroyed) 4705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return details; 4715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 4725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 4735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 4745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (event->IsMouseEvent()) { 4755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) PreDispatchMouseEvent(target_window, static_cast<ui::MouseEvent*>(event)); 4765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } else if (event->IsScrollEvent()) { 4775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) PreDispatchLocatedEvent(target_window, 4785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) static_cast<ui::ScrollEvent*>(event)); 4795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } else if (event->IsTouchEvent()) { 4805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) PreDispatchTouchEvent(target_window, static_cast<ui::TouchEvent*>(event)); 4815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 482a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) old_dispatch_target_ = event_dispatch_target_; 483a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) event_dispatch_target_ = static_cast<Window*>(target); 484a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) return DispatchDetails(); 485a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)} 486a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 487a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)ui::EventDispatchDetails WindowEventDispatcher::PostDispatchEvent( 488a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) ui::EventTarget* target, 489a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) const ui::Event& event) { 490a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) DispatchDetails details; 491a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) if (!target || target != event_dispatch_target_) 492a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) details.target_destroyed = true; 493a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) event_dispatch_target_ = old_dispatch_target_; 494a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) old_dispatch_target_ = NULL; 495a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#ifndef NDEBUG 496a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) DCHECK(!event_dispatch_target_ || window()->Contains(event_dispatch_target_)); 497a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#endif 4985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 4995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (event.IsTouchEvent() && !details.target_destroyed) { 500f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) // Do not let 'held' touch events contribute to any gestures unless it is 501f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) // being dispatched. 502f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) if (dispatching_held_event_ || !held_move_event_ || 503f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) !held_move_event_->IsTouchEvent()) { 5046e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) 5056e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) // Once we've fully migrated to the eager gesture detector, we won't 5066e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) // need to pass an event here. 5076e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) ui::TouchEvent orig_event(static_cast<const ui::TouchEvent&>(event), 5086e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) static_cast<Window*>(event.target()), 5096e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) window()); 5101320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 5111320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci if (event.result() & ui::ER_CONSUMED) 5121320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci orig_event.StopPropagation(); 5131320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 5141320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci // TODO(tdresser): Move this to PreDispatchTouchEvent, to enable eager 5151320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci // gesture detection. See crbug.com/410280. 5161320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci if (!ui::GestureRecognizer::Get() 5171320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci ->ProcessTouchEventPreDispatch(orig_event, 5181320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci static_cast<Window*>(target))) { 5191320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci return details; 5201320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci } 5211320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 5221320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci scoped_ptr<ui::GestureRecognizer::Gestures> gestures; 5231320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 5246e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) gestures.reset( 5256e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) ui::GestureRecognizer::Get()->ProcessTouchEventPostDispatch( 5266e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) orig_event, event.result(), static_cast<Window*>(target))); 5276e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) 5285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return ProcessGestures(gestures.get()); 5295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 5305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 5315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 532a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) return details; 533a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)} 534a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 5358bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)//////////////////////////////////////////////////////////////////////////////// 536a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// WindowEventDispatcher, ui::GestureEventHelper implementation: 5378bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 538a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)bool WindowEventDispatcher::CanDispatchToConsumer( 539a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) ui::GestureConsumer* consumer) { 540a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) Window* consumer_window = ConsumerToWindow(consumer); 541f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) return (consumer_window && consumer_window->GetRootWindow() == window()); 5428bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)} 5438bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 544a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void WindowEventDispatcher::DispatchCancelTouchEvent(ui::TouchEvent* event) { 5451320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci // The touchcancel event's location is based on the last known location of 5461320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci // the pointer, in dips. OnEventFromSource expects events with co-ordinates 5471320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci // in raw pixels, so we convert back to raw pixels here. 5481320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci event->UpdateForRootTransform(host_->GetRootTransform()); 5495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) DispatchDetails details = OnEventFromSource(event); 5505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (details.dispatcher_destroyed) 5515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return; 5525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 5535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5548bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)//////////////////////////////////////////////////////////////////////////////// 555effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch// WindowEventDispatcher, WindowObserver implementation: 556effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 557effb81e5f8246d0db0270817048dc992db66e9fbBen Murdochvoid WindowEventDispatcher::OnWindowDestroying(Window* window) { 558effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch if (!host_->window()->Contains(window)) 559effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch return; 560effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 561effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch DispatchMouseExitToHidingWindow(window); 562effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch SynthesizeMouseMoveAfterChangeToWindow(window); 563effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch} 564effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 565effb81e5f8246d0db0270817048dc992db66e9fbBen Murdochvoid WindowEventDispatcher::OnWindowDestroyed(Window* window) { 566effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch // We observe all windows regardless of what root Window (if any) they're 567effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch // attached to. 568effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch observer_manager_.Remove(window); 569effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch} 570effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 571effb81e5f8246d0db0270817048dc992db66e9fbBen Murdochvoid WindowEventDispatcher::OnWindowAddedToRootWindow(Window* attached) { 572effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch if (!observer_manager_.IsObserving(attached)) 573effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch observer_manager_.Add(attached); 574effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 575effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch if (!host_->window()->Contains(attached)) 576effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch return; 577effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 578effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch SynthesizeMouseMoveAfterChangeToWindow(attached); 579effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch} 580effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 581effb81e5f8246d0db0270817048dc992db66e9fbBen Murdochvoid WindowEventDispatcher::OnWindowRemovingFromRootWindow(Window* detached, 582effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch Window* new_root) { 583effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch if (!host_->window()->Contains(detached)) 584effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch return; 585effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 586effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch DCHECK(client::GetCaptureWindow(window()) != window()); 587effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 588effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch DispatchMouseExitToHidingWindow(detached); 589effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch SynthesizeMouseMoveAfterChangeToWindow(detached); 590effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 591effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch // Hiding the window releases capture which can implicitly destroy the window 592effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch // so the window may no longer be valid after this call. 593effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch OnWindowHidden(detached, new_root ? WINDOW_MOVING : WINDOW_HIDDEN); 594effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch} 595effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 596effb81e5f8246d0db0270817048dc992db66e9fbBen Murdochvoid WindowEventDispatcher::OnWindowVisibilityChanging(Window* window, 597effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch bool visible) { 598effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch if (!host_->window()->Contains(window)) 599effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch return; 600effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 601effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch DispatchMouseExitToHidingWindow(window); 602effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch} 603effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 604effb81e5f8246d0db0270817048dc992db66e9fbBen Murdochvoid WindowEventDispatcher::OnWindowVisibilityChanged(Window* window, 605effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch bool visible) { 606effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch if (!host_->window()->Contains(window)) 607effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch return; 608effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 609effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch if (window->ContainsPointInRoot(GetLastMouseLocationInRoot())) 6105c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu PostSynthesizeMouseMove(); 611effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 612effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch // Hiding the window releases capture which can implicitly destroy the window 613effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch // so the window may no longer be valid after this call. 614effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch if (!visible) 615effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch OnWindowHidden(window, WINDOW_HIDDEN); 616effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch} 617effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 618effb81e5f8246d0db0270817048dc992db66e9fbBen Murdochvoid WindowEventDispatcher::OnWindowBoundsChanged(Window* window, 619effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch const gfx::Rect& old_bounds, 620effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch const gfx::Rect& new_bounds) { 621effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch if (!host_->window()->Contains(window)) 622effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch return; 623effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 624effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch if (window == host_->window()) { 625effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch TRACE_EVENT1("ui", "WindowEventDispatcher::OnWindowBoundsChanged(root)", 626effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch "size", new_bounds.size().ToString()); 627effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 628effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch DispatchDetails details = DispatchHeldEvents(); 629effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch if (details.dispatcher_destroyed) 630effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch return; 631effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 632effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch synthesize_mouse_move_ = false; 633effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch } 634effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 6350529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch if (window->IsVisible() && !window->ignore_events()) { 636effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch gfx::Rect old_bounds_in_root = old_bounds, new_bounds_in_root = new_bounds; 637effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch Window::ConvertRectToTarget(window->parent(), host_->window(), 638effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch &old_bounds_in_root); 639effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch Window::ConvertRectToTarget(window->parent(), host_->window(), 640effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch &new_bounds_in_root); 641effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch gfx::Point last_mouse_location = GetLastMouseLocationInRoot(); 642effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch if (old_bounds_in_root.Contains(last_mouse_location) != 643effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch new_bounds_in_root.Contains(last_mouse_location)) { 6445c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu PostSynthesizeMouseMove(); 645effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch } 646effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch } 647effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch} 648effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 649effb81e5f8246d0db0270817048dc992db66e9fbBen Murdochvoid WindowEventDispatcher::OnWindowTransforming(Window* window) { 650effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch if (!host_->window()->Contains(window)) 651effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch return; 652effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 653effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch SynthesizeMouseMoveAfterChangeToWindow(window); 654effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch} 655effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 656effb81e5f8246d0db0270817048dc992db66e9fbBen Murdochvoid WindowEventDispatcher::OnWindowTransformed(Window* window) { 657effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch if (!host_->window()->Contains(window)) 658effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch return; 659effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 660effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch SynthesizeMouseMoveAfterChangeToWindow(window); 661effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch} 662effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 663effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch/////////////////////////////////////////////////////////////////////////////// 664effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch// WindowEventDispatcher, EnvObserver implementation: 665effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 666effb81e5f8246d0db0270817048dc992db66e9fbBen Murdochvoid WindowEventDispatcher::OnWindowInitialized(Window* window) { 667effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch observer_manager_.Add(window); 668effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch} 669effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 670effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch//////////////////////////////////////////////////////////////////////////////// 671a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// WindowEventDispatcher, private: 6725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 673a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)ui::EventDispatchDetails WindowEventDispatcher::DispatchHeldEvents() { 6745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (!held_repostable_event_ && !held_move_event_) 6755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return DispatchDetails(); 6765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 6775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) CHECK(!dispatching_held_event_); 6785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) dispatching_held_event_ = true; 6795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 6805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) DispatchDetails dispatch_details; 6815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (held_repostable_event_) { 6825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (held_repostable_event_->type() == ui::ET_MOUSE_PRESSED) { 6835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) scoped_ptr<ui::MouseEvent> mouse_event( 6845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) static_cast<ui::MouseEvent*>(held_repostable_event_.release())); 6855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) dispatch_details = OnEventFromSource(mouse_event.get()); 686f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) } else { 6875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // TODO(rbyers): GESTURE_TAP_DOWN not yet supported: crbug.com/170987. 6885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) NOTREACHED(); 689f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) } 6905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (dispatch_details.dispatcher_destroyed) 6915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return dispatch_details; 692f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) } 6935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 6945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (held_move_event_) { 6955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // If a mouse move has been synthesized, the target location is suspect, 6965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // so drop the held mouse event. 6975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (held_move_event_->IsTouchEvent() || 6985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) (held_move_event_->IsMouseEvent() && !synthesize_mouse_move_)) { 6995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) dispatch_details = OnEventFromSource(held_move_event_.get()); 7005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 7015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (!dispatch_details.dispatcher_destroyed) 7025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) held_move_event_.reset(); 7035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 7045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 7055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (!dispatch_details.dispatcher_destroyed) 7065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) dispatching_held_event_ = false; 7075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return dispatch_details; 708f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)} 709f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 7105c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liuvoid WindowEventDispatcher::PostSynthesizeMouseMove() { 7115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (synthesize_mouse_move_) 7125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return; 7135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) synthesize_mouse_move_ = true; 7145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::MessageLoop::current()->PostNonNestableTask( 7155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) FROM_HERE, 716a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) base::Bind(base::IgnoreResult( 717a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) &WindowEventDispatcher::SynthesizeMouseMoveEvent), 7185c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu held_event_factory_.GetWeakPtr())); 7195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 7205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 721effb81e5f8246d0db0270817048dc992db66e9fbBen Murdochvoid WindowEventDispatcher::SynthesizeMouseMoveAfterChangeToWindow( 722effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch Window* window) { 723effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch if (window->IsVisible() && 724effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch window->ContainsPointInRoot(GetLastMouseLocationInRoot())) { 7255c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu PostSynthesizeMouseMove(); 726effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch } 727effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch} 728effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 7295c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liuui::EventDispatchDetails WindowEventDispatcher::SynthesizeMouseMoveEvent() { 7305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) DispatchDetails details; 7315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (!synthesize_mouse_move_) 7325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return details; 7335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) synthesize_mouse_move_ = false; 734116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 735116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // If one of the mouse buttons is currently down, then do not synthesize a 736116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // mouse-move event. In such cases, aura could synthesize a DRAGGED event 737116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // instead of a MOVED event, but in multi-display/multi-host scenarios, the 738116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // DRAGGED event can be synthesized in the incorrect host. So avoid 739116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // synthesizing any events at all. 740116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch if (Env::GetInstance()->mouse_button_flags()) 741116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch return details; 742116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 7435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) gfx::Point root_mouse_location = GetLastMouseLocationInRoot(); 7445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (!window()->bounds().Contains(root_mouse_location)) 7455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return details; 7465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) gfx::Point host_mouse_location = root_mouse_location; 74723730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) host_->ConvertPointToHost(&host_mouse_location); 7485c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu ui::MouseEvent event(ui::ET_MOUSE_MOVED, 7495c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu host_mouse_location, 7505c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu host_mouse_location, 7515c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu ui::EF_IS_SYNTHESIZED, 7525c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu 0); 7535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return OnEventFromSource(&event); 7545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 7555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 756a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void WindowEventDispatcher::PreDispatchLocatedEvent(Window* target, 757a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) ui::LocatedEvent* event) { 7585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) int flags = event->flags(); 7595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (IsNonClientLocation(target, event->location())) 7605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) flags |= ui::EF_IS_NON_CLIENT; 7615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) event->set_flags(flags); 7625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 7635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (!dispatching_held_event_ && 7645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) (event->IsMouseEvent() || event->IsScrollEvent()) && 7655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) !(event->flags() & ui::EF_IS_SYNTHESIZED)) { 7665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (event->type() != ui::ET_MOUSE_CAPTURE_CHANGED) 7675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) SetLastMouseLocation(window(), event->root_location()); 7685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) synthesize_mouse_move_ = false; 7694e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) } 7702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 7712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 772a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void WindowEventDispatcher::PreDispatchMouseEvent(Window* target, 773a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) ui::MouseEvent* event) { 774f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) client::CursorClient* cursor_client = client::GetCursorClient(window()); 775c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch // We allow synthesized mouse exit events through even if mouse events are 776c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch // disabled. This ensures that hover state, etc on controls like buttons is 777c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch // cleared. 778eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch if (cursor_client && 779eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch !cursor_client->IsMouseEventsEnabled() && 780c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch (event->flags() & ui::EF_IS_SYNTHESIZED) && 781c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch (event->type() != ui::ET_MOUSE_EXITED)) { 7825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) event->SetHandled(); 7835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return; 7845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 785eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 7865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (IsEventCandidateForHold(*event) && !dispatching_held_event_) { 7875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (move_hold_count_) { 7885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (!(event->flags() & ui::EF_IS_SYNTHESIZED) && 7895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) event->type() != ui::ET_MOUSE_CAPTURE_CHANGED) { 7905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) SetLastMouseLocation(window(), event->root_location()); 7915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 7925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) held_move_event_.reset(new ui::MouseEvent(*event, target, window())); 7935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) event->SetHandled(); 7945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return; 7955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } else { 7965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // We may have a held event for a period between the time move_hold_count_ 7975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // fell to 0 and the DispatchHeldEvents executes. Since we're going to 7985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // dispatch the new event directly below, we can reset the old one. 7995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) held_move_event_.reset(); 8005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 8015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 8025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 8035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const int kMouseButtonFlagMask = ui::EF_LEFT_MOUSE_BUTTON | 8045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ui::EF_MIDDLE_MOUSE_BUTTON | 8055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ui::EF_RIGHT_MOUSE_BUTTON; 8065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) switch (event->type()) { 8072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) case ui::ET_MOUSE_EXITED: 8085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (!target || target == window()) { 809f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) DispatchDetails details = 810f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) DispatchMouseEnterOrExit(*event, ui::ET_MOUSE_EXITED); 8115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (details.dispatcher_destroyed) { 8125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) event->SetHandled(); 8135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return; 8145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 8158bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) mouse_moved_handler_ = NULL; 8162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 8172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) break; 8185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) case ui::ET_MOUSE_MOVED: 81958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) // Send an exit to the current |mouse_moved_handler_| and an enter to 82058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) // |target|. Take care that both us and |target| aren't destroyed during 82158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) // dispatch. 82258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) if (target != mouse_moved_handler_) { 82358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) aura::Window* old_mouse_moved_handler = mouse_moved_handler_; 8245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) WindowTracker live_window; 8255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) live_window.Add(target); 826f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) DispatchDetails details = 827f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) DispatchMouseEnterOrExit(*event, ui::ET_MOUSE_EXITED); 8285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (details.dispatcher_destroyed) { 8295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) event->SetHandled(); 8305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return; 8315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 83258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) // If the |mouse_moved_handler_| changes out from under us, assume a 83358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) // nested message loop ran and we don't need to do anything. 8345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (mouse_moved_handler_ != old_mouse_moved_handler) { 8355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) event->SetHandled(); 8365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return; 8375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 8385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (!live_window.Contains(target) || details.target_destroyed) { 8398bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) mouse_moved_handler_ = NULL; 8405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) event->SetHandled(); 8415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return; 8425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 8435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) live_window.Remove(target); 8445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 8455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) mouse_moved_handler_ = target; 8465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) details = DispatchMouseEnterOrExit(*event, ui::ET_MOUSE_ENTERED); 8475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (details.dispatcher_destroyed || details.target_destroyed) { 8485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) event->SetHandled(); 8495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return; 85058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) } 85158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) } 8525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) break; 8535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) case ui::ET_MOUSE_PRESSED: 8542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Don't set the mouse pressed handler for non client mouse down events. 8552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // These are only sent by Windows and are not always followed with non 8562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // client mouse up events which causes subsequent mouse events to be 8572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // sent to the wrong target. 8582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (!(event->flags() & ui::EF_IS_NON_CLIENT) && !mouse_pressed_handler_) 8595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) mouse_pressed_handler_ = target; 860eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch Env::GetInstance()->set_mouse_button_flags( 861eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch event->flags() & kMouseButtonFlagMask); 8625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) break; 8635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) case ui::ET_MOUSE_RELEASED: 8645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) mouse_pressed_handler_ = NULL; 865eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch Env::GetInstance()->set_mouse_button_flags(event->flags() & 866eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch kMouseButtonFlagMask & ~event->changed_button_flags()); 8675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) break; 8685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) default: 8695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) break; 8705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 8715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 8725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) PreDispatchLocatedEvent(target, event); 8735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 8745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 875a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void WindowEventDispatcher::PreDispatchTouchEvent(Window* target, 876a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) ui::TouchEvent* event) { 8777d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) switch (event->type()) { 8787d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) case ui::ET_TOUCH_PRESSED: 8797d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) touch_ids_down_ |= (1 << event->touch_id()); 8807d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) Env::GetInstance()->set_touch_down(touch_ids_down_ != 0); 8817d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) break; 8827d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 8837d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // Handle ET_TOUCH_CANCELLED only if it has a native event. 8847d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) case ui::ET_TOUCH_CANCELLED: 8857d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) if (!event->HasNativeEvent()) 8867d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) break; 8877d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // fallthrough 8887d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) case ui::ET_TOUCH_RELEASED: 8897d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) touch_ids_down_ = (touch_ids_down_ | (1 << event->touch_id())) ^ 8907d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) (1 << event->touch_id()); 8917d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) Env::GetInstance()->set_touch_down(touch_ids_down_ != 0); 8927d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) break; 8937d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 8945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) case ui::ET_TOUCH_MOVED: 8955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (move_hold_count_ && !dispatching_held_event_) { 8965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) held_move_event_.reset(new ui::TouchEvent(*event, target, window())); 8975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) event->SetHandled(); 8985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return; 8995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 9007d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) break; 9017d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 9025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) default: 9031e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) NOTREACHED(); 9045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) break; 9055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 9066e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) 9075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) PreDispatchLocatedEvent(target, event); 9085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 9095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace aura 911