window_event_dispatcher.cc revision a1401311d1ab56c4ed0a474bd38c108f75cb0cd9
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), 85f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) repost_event_factory_(this), 860f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) held_event_factory_(this) { 878bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) ui::GestureRecognizer::Get()->AddGestureEventHelper(this); 885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 90a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)WindowEventDispatcher::~WindowEventDispatcher() { 91a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) TRACE_EVENT0("shutdown", "WindowEventDispatcher::Destructor"); 928bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) ui::GestureRecognizer::Get()->RemoveGestureEventHelper(this); 935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 95a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void WindowEventDispatcher::PrepareForShutdown() { 965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) host_->PrepareForShutdown(); 975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // discard synthesize event request as well. 985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) synthesize_mouse_move_ = false; 995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 101a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void WindowEventDispatcher::RepostEvent(const ui::LocatedEvent& event) { 1023551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) DCHECK(event.type() == ui::ET_MOUSE_PRESSED || 1033551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) event.type() == ui::ET_GESTURE_TAP_DOWN); 1042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // We allow for only one outstanding repostable event. This is used 1052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // in exiting context menus. A dropped repost request is allowed. 1062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (event.type() == ui::ET_MOUSE_PRESSED) { 1072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) held_repostable_event_.reset( 1082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) new ui::MouseEvent( 1092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) static_cast<const ui::MouseEvent&>(event), 1102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) static_cast<aura::Window*>(event.target()), 111f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) window())); 1125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::MessageLoop::current()->PostNonNestableTask( 113a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) FROM_HERE, base::Bind( 114a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) base::IgnoreResult(&WindowEventDispatcher::DispatchHeldEvents), 115a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) repost_event_factory_.GetWeakPtr())); 1162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } else { 1171e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) DCHECK(event.type() == ui::ET_GESTURE_TAP_DOWN); 1181e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) held_repostable_event_.reset(); 1191e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // TODO(rbyers): Reposing of gestures is tricky to get 1201e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // right, so it's not yet supported. crbug.com/170987. 1212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 1222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 1232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 124a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void WindowEventDispatcher::OnMouseEventsEnableStateChanged(bool enabled) { 1255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Send entered / exited so that visual state can be updated to match 1262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // mouse events state. 1275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) PostMouseMoveEventAfterWindowChange(); 1282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // TODO(mazda): Add code to disable mouse events when |enabled| == false. 1295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 131a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void WindowEventDispatcher::DispatchCancelModeEvent() { 132a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) ui::CancelModeEvent event; 133a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) Window* focused_window = client::GetFocusClient(window())->GetFocusedWindow(); 134a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) if (focused_window && !window()->Contains(focused_window)) 135a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) focused_window = NULL; 136a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) DispatchDetails details = 137a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) DispatchEvent(focused_window ? focused_window : window(), &event); 138a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) if (details.dispatcher_destroyed) 139a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) return; 140a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)} 141a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 142a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)Window* WindowEventDispatcher::GetGestureTarget(ui::GestureEvent* event) { 143a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) Window* target = NULL; 144a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) if (!event->IsEndingEvent()) { 145a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // The window that received the start event (e.g. scroll begin) needs to 146a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // receive the end event (e.g. scroll end). 147a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) target = client::GetCaptureWindow(window()); 148a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) } 1495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (!target) { 1505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) target = ConsumerToWindow( 151a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ui::GestureRecognizer::Get()->GetTargetForGestureEvent(*event)); 1525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return target; 1552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 1562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 157a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void WindowEventDispatcher::DispatchGestureEvent(ui::GestureEvent* event) { 158f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) DispatchDetails details = DispatchHeldEvents(); 159f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) if (details.dispatcher_destroyed) 160f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) return; 1612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Window* target = GetGestureTarget(event); 1635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (target) { 164f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) event->ConvertLocationToTarget(window(), target); 165a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) DispatchDetails details = DispatchEvent(target, event); 166f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) if (details.dispatcher_destroyed) 167f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) return; 1685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 171a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void WindowEventDispatcher::OnWindowDestroying(Window* window) { 17290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) DispatchMouseExitToHidingWindow(window); 1735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (window->IsVisible() && 1745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window->ContainsPointInRoot(GetLastMouseLocationInRoot())) { 1755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) PostMouseMoveEventAfterWindowChange(); 1765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Hiding the window releases capture which can implicitly destroy the window 1795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // so the window may no longer be valid after this call. 1805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) OnWindowHidden(window, WINDOW_DESTROYED); 1815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 183a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void WindowEventDispatcher::OnWindowBoundsChanged(Window* window, 184a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) bool contained_mouse_point) { 1855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (contained_mouse_point || 1865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) (window->IsVisible() && 1875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window->ContainsPointInRoot(GetLastMouseLocationInRoot()))) { 1885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) PostMouseMoveEventAfterWindowChange(); 1895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 192a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void WindowEventDispatcher::DispatchMouseExitToHidingWindow(Window* window) { 19390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // The mouse capture is intentionally ignored. Think that a mouse enters 19490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // to a window, the window sets the capture, the mouse exits the window, 19590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // and then it releases the capture. In that case OnMouseExited won't 19690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // be called. So it is natural not to emit OnMouseExited even though 19790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // |window| is the capture window. 19890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) gfx::Point last_mouse_location = GetLastMouseLocationInRoot(); 19990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) if (window->Contains(mouse_moved_handler_) && 20068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) window->ContainsPointInRoot(last_mouse_location)) 20168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) DispatchMouseExitAtPoint(last_mouse_location); 20268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)} 20368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 204a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void WindowEventDispatcher::DispatchMouseExitAtPoint(const gfx::Point& point) { 2055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ui::MouseEvent event(ui::ET_MOUSE_EXITED, point, point, ui::EF_NONE, 2065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ui::EF_NONE); 207f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) DispatchDetails details = 208f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) DispatchMouseEnterOrExit(event, ui::ET_MOUSE_EXITED); 209f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) if (details.dispatcher_destroyed) 210f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) return; 21190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)} 21290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 213a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void WindowEventDispatcher::OnWindowVisibilityChanged(Window* window, 214a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) bool is_visible) { 2155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (window->ContainsPointInRoot(GetLastMouseLocationInRoot())) 2165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) PostMouseMoveEventAfterWindowChange(); 2175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Hiding the window releases capture which can implicitly destroy the window 2195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // so the window may no longer be valid after this call. 2205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (!is_visible) 2215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) OnWindowHidden(window, WINDOW_HIDDEN); 2225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 224a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void WindowEventDispatcher::OnWindowTransformed(Window* window, 225a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) bool contained_mouse) { 2265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (contained_mouse || 2275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) (window->IsVisible() && 2285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window->ContainsPointInRoot(GetLastMouseLocationInRoot()))) { 2295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) PostMouseMoveEventAfterWindowChange(); 2305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 2315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 233a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void WindowEventDispatcher::ProcessedTouchEvent(ui::TouchEvent* event, 234a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) Window* window, 235a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) ui::EventResult result) { 2365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_ptr<ui::GestureRecognizer::Gestures> gestures; 2378bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) gestures.reset(ui::GestureRecognizer::Get()-> 2388bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) ProcessTouchEventForGesture(*event, result, window)); 239f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) DispatchDetails details = ProcessGestures(gestures.get()); 240f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) if (details.dispatcher_destroyed) 241f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) return; 2425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 244a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void WindowEventDispatcher::HoldPointerMoves() { 2457d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) if (!move_hold_count_) 2462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) held_event_factory_.InvalidateWeakPtrs(); 2477d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) ++move_hold_count_; 248a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) TRACE_EVENT_ASYNC_BEGIN0("ui", "WindowEventDispatcher::HoldPointerMoves", 249a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) this); 2507d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)} 2517d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 252a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void WindowEventDispatcher::ReleasePointerMoves() { 2537d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) --move_hold_count_; 2547d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) DCHECK_GE(move_hold_count_, 0); 2557d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) if (!move_hold_count_ && held_move_event_) { 2567d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // We don't want to call DispatchHeldEvents directly, because this might be 2577d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // called from a deep stack while another event, in which case dispatching 2587d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // another one may not be safe/expected. Instead we post a task, that we 2597d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // may cancel if HoldPointerMoves is called again before it executes. 2605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::MessageLoop::current()->PostNonNestableTask( 261a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) FROM_HERE, base::Bind( 262a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) base::IgnoreResult(&WindowEventDispatcher::DispatchHeldEvents), 263a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) held_event_factory_.GetWeakPtr())); 2645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 265a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) TRACE_EVENT_ASYNC_END0("ui", "WindowEventDispatcher::HoldPointerMoves", this); 2665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 268a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)gfx::Point WindowEventDispatcher::GetLastMouseLocationInRoot() const { 2695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Point location = Env::GetInstance()->last_mouse_location(); 270f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) client::ScreenPositionClient* client = 271f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) client::GetScreenPositionClient(window()); 2725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (client) 273f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) client->ConvertPointFromScreen(window(), &location); 2745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return location; 2755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 277a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void WindowEventDispatcher::OnHostLostMouseGrab() { 278a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) mouse_pressed_handler_ = NULL; 279a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) mouse_moved_handler_ = NULL; 280a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)} 281a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 282a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void WindowEventDispatcher::OnHostResized(const gfx::Size& size) { 283a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) TRACE_EVENT1("ui", "WindowEventDispatcher::OnHostResized", 284a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) "size", size.ToString()); 285a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 286a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) DispatchDetails details = DispatchHeldEvents(); 287a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) if (details.dispatcher_destroyed) 288a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) return; 289a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 290a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // Constrain the mouse position within the new root Window size. 291a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) gfx::Point point; 292a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) if (host_->QueryMouseLocation(&point)) { 293a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) SetLastMouseLocation(window(), 294a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) ui::ConvertPointToDIP(window()->layer(), point)); 295a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) } 296a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) synthesize_mouse_move_ = false; 297a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)} 298a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 299a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void WindowEventDispatcher::OnCursorMovedToRootLocation( 300a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) const gfx::Point& root_location) { 301a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) SetLastMouseLocation(window(), root_location); 302a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) synthesize_mouse_move_ = false; 303a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)} 304a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 3055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//////////////////////////////////////////////////////////////////////////////// 306a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// WindowEventDispatcher, private: 3075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 308a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void WindowEventDispatcher::TransformEventForDeviceScaleFactor( 309a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) ui::LocatedEvent* event) { 3105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) event->UpdateForRootTransform(host()->GetInverseRootTransform()); 3112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 3122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 313a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)ui::EventDispatchDetails WindowEventDispatcher::DispatchMouseEnterOrExit( 314f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) const ui::MouseEvent& event, 315f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) ui::EventType type) { 3165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (event.type() != ui::ET_MOUSE_CAPTURE_CHANGED && 3175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) !(event.flags() & ui::EF_IS_SYNTHESIZED)) { 3185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) SetLastMouseLocation(window(), event.root_location()); 3195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 3205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 3212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (!mouse_moved_handler_ || !mouse_moved_handler_->delegate()) 322f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) return DispatchDetails(); 3235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // |event| may be an event in the process of being dispatched to a target (in 3255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // which case its locations will be in the event's target's coordinate 3265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // system), or a synthetic event created in root-window (in which case, the 3275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // event's target will be NULL, and the event will be in the root-window's 3285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // coordinate system. 3295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) aura::Window* target = static_cast<Window*>(event.target()); 3305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (!target) 3315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) target = window(); 3322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ui::MouseEvent translated_event(event, 3335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) target, 3342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) mouse_moved_handler_, 3352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) type, 336eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch event.flags() | ui::EF_IS_SYNTHESIZED); 337a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) return DispatchEvent(mouse_moved_handler_, &translated_event); 3385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 3395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 340a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)ui::EventDispatchDetails WindowEventDispatcher::ProcessGestures( 341f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) ui::GestureRecognizer::Gestures* gestures) { 342f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) DispatchDetails details; 3432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (!gestures || gestures->empty()) 344f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) return details; 3452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 3462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Window* target = GetGestureTarget(gestures->get().at(0)); 3472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) for (size_t i = 0; i < gestures->size(); ++i) { 3482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ui::GestureEvent* event = gestures->get().at(i); 349f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) event->ConvertLocationToTarget(window(), target); 350a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) details = DispatchEvent(target, event); 351f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) if (details.dispatcher_destroyed || details.target_destroyed) 3522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) break; 3535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 354f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) return details; 3555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 3565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 357a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void WindowEventDispatcher::OnWindowAddedToRootWindow(Window* attached) { 3588bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) if (attached->IsVisible() && 3598bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) attached->ContainsPointInRoot(GetLastMouseLocationInRoot())) { 3608bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) PostMouseMoveEventAfterWindowChange(); 3618bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) } 3628bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)} 3638bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 364a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void WindowEventDispatcher::OnWindowRemovedFromRootWindow(Window* detached, 365a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) Window* new_root) { 366f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) DCHECK(aura::client::GetCaptureWindow(window()) != window()); 3675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 36890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) DispatchMouseExitToHidingWindow(detached); 3695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (detached->IsVisible() && 3705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) detached->ContainsPointInRoot(GetLastMouseLocationInRoot())) { 3715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) PostMouseMoveEventAfterWindowChange(); 3725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 3735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 3745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Hiding the window releases capture which can implicitly destroy the window 3755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // so the window may no longer be valid after this call. 3765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) OnWindowHidden(detached, new_root ? WINDOW_MOVING : WINDOW_HIDDEN); 3775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 3785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 379a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void WindowEventDispatcher::OnWindowHidden(Window* invisible, 380a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) WindowHiddenReason reason) { 3815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // If the window the mouse was pressed in becomes invisible, it should no 3825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // longer receive mouse events. 3835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (invisible->Contains(mouse_pressed_handler_)) 3845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) mouse_pressed_handler_ = NULL; 3855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (invisible->Contains(mouse_moved_handler_)) 3865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) mouse_moved_handler_ = NULL; 3875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 388a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // If events are being dispatched from a nested message-loop, and the target 389a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // of the outer loop is hidden or moved to another dispatcher during 390a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // dispatching events in the inner loop, then reset the target for the outer 391a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // loop. 392a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) if (invisible->Contains(old_dispatch_target_)) 393a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) old_dispatch_target_ = NULL; 394a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 3955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) CleanupGestureState(invisible); 3965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 3972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Do not clear the capture, and the |event_dispatch_target_| if the 3982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // window is moving across root windows, because the target itself 3992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // is actually still visible and clearing them stops further event 4002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // processing, which can cause unexpected behaviors. See 4012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // crbug.com/157583 4025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (reason != WINDOW_MOVING) { 403f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) Window* capture_window = aura::client::GetCaptureWindow(window()); 4045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (invisible->Contains(event_dispatch_target_)) 4065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) event_dispatch_target_ = NULL; 4075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // If the ancestor of the capture window is hidden, release the capture. 4095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Note that this may delete the window so do not use capture_window 4105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // after this. 4115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (invisible->Contains(capture_window) && invisible != window()) 4125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) capture_window->ReleaseCapture(); 4135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 4145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 4155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 416a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void WindowEventDispatcher::CleanupGestureState(Window* window) { 417f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) ui::GestureRecognizer::Get()->CancelActiveTouches(window); 4188bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) ui::GestureRecognizer::Get()->CleanupStateForConsumer(window); 419f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) const Window::Windows& windows = window->children(); 420f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) for (Window::Windows::const_iterator iter = windows.begin(); 4215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) iter != windows.end(); 4225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ++iter) { 423f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) CleanupGestureState(*iter); 4245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 4255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 4265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4278bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)//////////////////////////////////////////////////////////////////////////////// 428a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// WindowEventDispatcher, aura::client::CaptureDelegate implementation: 4298bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 430a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void WindowEventDispatcher::UpdateCapture(Window* old_capture, 431a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) Window* new_capture) { 4328bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // |mouse_moved_handler_| may have been set to a Window in a different root 4338bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // (see below). Clear it here to ensure we don't end up referencing a stale 4348bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // Window. 435f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) if (mouse_moved_handler_ && !window()->Contains(mouse_moved_handler_)) 4368bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) mouse_moved_handler_ = NULL; 4378bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 438f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) if (old_capture && old_capture->GetRootWindow() == window() && 4398bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) old_capture->delegate()) { 4408bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // Send a capture changed event with bogus location data. 4418bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) ui::MouseEvent event(ui::ET_MOUSE_CAPTURE_CHANGED, gfx::Point(), 4425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) gfx::Point(), 0, 0); 4438bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 444a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) DispatchDetails details = DispatchEvent(old_capture, &event); 445f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) if (details.dispatcher_destroyed) 446f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) return; 4478bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 4488bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) old_capture->delegate()->OnCaptureLost(); 4498bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) } 4508bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 4518bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) if (new_capture) { 4528bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // Make all subsequent mouse events go to the capture window. We shouldn't 4538bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // need to send an event here as OnCaptureLost() should take care of that. 4548bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) if (mouse_moved_handler_ || Env::GetInstance()->IsMouseButtonDown()) 4558bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) mouse_moved_handler_ = new_capture; 4568bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) } else { 4578bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // Make sure mouse_moved_handler gets updated. 458f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) DispatchDetails details = SynthesizeMouseMoveEvent(); 459f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) if (details.dispatcher_destroyed) 460f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) return; 4618bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) } 4628bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) mouse_pressed_handler_ = NULL; 4638bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)} 4648bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 465a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void WindowEventDispatcher::OnOtherRootGotCapture() { 4661e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) mouse_moved_handler_ = NULL; 4671e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) mouse_pressed_handler_ = NULL; 4681e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} 4691e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 470a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void WindowEventDispatcher::SetNativeCapture() { 4718bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) host_->SetCapture(); 4728bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)} 4738bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 474a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void WindowEventDispatcher::ReleaseNativeCapture() { 4758bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) host_->ReleaseCapture(); 4768bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)} 4778bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 4788bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)//////////////////////////////////////////////////////////////////////////////// 479a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// WindowEventDispatcher, ui::EventProcessor implementation: 480a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)ui::EventTarget* WindowEventDispatcher::GetRootTarget() { 481a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) return window(); 482a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)} 483a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 484a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void WindowEventDispatcher::PrepareEventForDispatch(ui::Event* event) { 4855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (dispatching_held_event_) { 4865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // The held events are already in |window()|'s coordinate system. So it is 4875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // not necessary to apply the transform to convert from the host's 4885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // coordinate system to |window()|'s coordinate system. 4895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return; 4905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 4915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (event->IsMouseEvent() || 4925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) event->IsScrollEvent() || 4935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) event->IsTouchEvent() || 4945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) event->IsGestureEvent()) { 4955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) TransformEventForDeviceScaleFactor(static_cast<ui::LocatedEvent*>(event)); 4965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 4975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 4985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 499a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)//////////////////////////////////////////////////////////////////////////////// 500a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// WindowEventDispatcher, ui::EventDispatcherDelegate implementation: 5018bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 502a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)bool WindowEventDispatcher::CanDispatchToTarget(ui::EventTarget* target) { 5035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return event_dispatch_target_ == target; 5045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 5055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 506a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)ui::EventDispatchDetails WindowEventDispatcher::PreDispatchEvent( 507a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) ui::EventTarget* target, 508a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) ui::Event* event) { 509a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) Window* target_window = static_cast<Window*>(target); 510a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) CHECK(window()->Contains(target_window)); 511a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 5125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (!dispatching_held_event_) { 5135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) bool can_be_held = IsEventCandidateForHold(*event); 5145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (!move_hold_count_ || !can_be_held) { 5155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (can_be_held) 5165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) held_move_event_.reset(); 5175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) DispatchDetails details = DispatchHeldEvents(); 5185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (details.dispatcher_destroyed || details.target_destroyed) 5195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return details; 5205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 5215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 5225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 5235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (event->IsMouseEvent()) { 5245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) PreDispatchMouseEvent(target_window, static_cast<ui::MouseEvent*>(event)); 5255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } else if (event->IsScrollEvent()) { 5265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) PreDispatchLocatedEvent(target_window, 5275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) static_cast<ui::ScrollEvent*>(event)); 5285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } else if (event->IsTouchEvent()) { 5295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) PreDispatchTouchEvent(target_window, static_cast<ui::TouchEvent*>(event)); 5305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 531a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) old_dispatch_target_ = event_dispatch_target_; 532a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) event_dispatch_target_ = static_cast<Window*>(target); 533a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) return DispatchDetails(); 534a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)} 535a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 536a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)ui::EventDispatchDetails WindowEventDispatcher::PostDispatchEvent( 537a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) ui::EventTarget* target, 538a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) const ui::Event& event) { 539a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) DispatchDetails details; 540a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) if (!target || target != event_dispatch_target_) 541a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) details.target_destroyed = true; 542a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) event_dispatch_target_ = old_dispatch_target_; 543a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) old_dispatch_target_ = NULL; 544a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#ifndef NDEBUG 545a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) DCHECK(!event_dispatch_target_ || window()->Contains(event_dispatch_target_)); 546a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#endif 5475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 5485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (event.IsTouchEvent() && !details.target_destroyed) { 5495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Do not let 'held' touch events contribute to any gestures. 5505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (!held_move_event_ || !held_move_event_->IsTouchEvent()) { 5515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ui::TouchEvent orig_event(static_cast<const ui::TouchEvent&>(event), 5525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) static_cast<Window*>(event.target()), window()); 5535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Get the list of GestureEvents from GestureRecognizer. 5545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) scoped_ptr<ui::GestureRecognizer::Gestures> gestures; 5555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) gestures.reset(ui::GestureRecognizer::Get()-> 5565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ProcessTouchEventForGesture(orig_event, event.result(), 5575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) static_cast<Window*>(target))); 5585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return ProcessGestures(gestures.get()); 5595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 5605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 5615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 562a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) return details; 563a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)} 564a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 5658bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)//////////////////////////////////////////////////////////////////////////////// 566a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// WindowEventDispatcher, ui::GestureEventHelper implementation: 5678bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 568a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)bool WindowEventDispatcher::CanDispatchToConsumer( 569a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) ui::GestureConsumer* consumer) { 570a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) Window* consumer_window = ConsumerToWindow(consumer); 571f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) return (consumer_window && consumer_window->GetRootWindow() == window()); 5728bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)} 5738bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 574a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void WindowEventDispatcher::DispatchPostponedGestureEvent( 575a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) ui::GestureEvent* event) { 5768bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) DispatchGestureEvent(event); 5775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 5785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 579a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void WindowEventDispatcher::DispatchCancelTouchEvent(ui::TouchEvent* event) { 5805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) DispatchDetails details = OnEventFromSource(event); 5815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (details.dispatcher_destroyed) 5825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return; 5835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 5845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5858bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)//////////////////////////////////////////////////////////////////////////////// 586a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// WindowEventDispatcher, private: 5875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 588a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)ui::EventDispatchDetails WindowEventDispatcher::DispatchHeldEvents() { 5895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (!held_repostable_event_ && !held_move_event_) 5905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return DispatchDetails(); 5915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 5925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) CHECK(!dispatching_held_event_); 5935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) dispatching_held_event_ = true; 5945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 5955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) DispatchDetails dispatch_details; 5965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (held_repostable_event_) { 5975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (held_repostable_event_->type() == ui::ET_MOUSE_PRESSED) { 5985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) scoped_ptr<ui::MouseEvent> mouse_event( 5995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) static_cast<ui::MouseEvent*>(held_repostable_event_.release())); 6005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) dispatch_details = OnEventFromSource(mouse_event.get()); 601f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) } else { 6025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // TODO(rbyers): GESTURE_TAP_DOWN not yet supported: crbug.com/170987. 6035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) NOTREACHED(); 604f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) } 6055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (dispatch_details.dispatcher_destroyed) 6065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return dispatch_details; 607f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) } 6085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 6095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (held_move_event_) { 6105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // If a mouse move has been synthesized, the target location is suspect, 6115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // so drop the held mouse event. 6125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (held_move_event_->IsTouchEvent() || 6135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) (held_move_event_->IsMouseEvent() && !synthesize_mouse_move_)) { 6145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) dispatch_details = OnEventFromSource(held_move_event_.get()); 6155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 6165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (!dispatch_details.dispatcher_destroyed) 6175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) held_move_event_.reset(); 6185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 6195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 6205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (!dispatch_details.dispatcher_destroyed) 6215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) dispatching_held_event_ = false; 6225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return dispatch_details; 623f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)} 624f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 625a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void WindowEventDispatcher::PostMouseMoveEventAfterWindowChange() { 6265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (synthesize_mouse_move_) 6275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return; 6285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) synthesize_mouse_move_ = true; 6295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::MessageLoop::current()->PostNonNestableTask( 6305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) FROM_HERE, 631a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) base::Bind(base::IgnoreResult( 632a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) &WindowEventDispatcher::SynthesizeMouseMoveEvent), 633a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) held_event_factory_.GetWeakPtr())); 6345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 6355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 636a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)ui::EventDispatchDetails WindowEventDispatcher::SynthesizeMouseMoveEvent() { 6375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) DispatchDetails details; 6385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (!synthesize_mouse_move_) 6395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return details; 6405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) synthesize_mouse_move_ = false; 6415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) gfx::Point root_mouse_location = GetLastMouseLocationInRoot(); 6425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (!window()->bounds().Contains(root_mouse_location)) 6435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return details; 6445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) gfx::Point host_mouse_location = root_mouse_location; 6455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) host()->ConvertPointToHost(&host_mouse_location); 6465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ui::MouseEvent event(ui::ET_MOUSE_MOVED, 6475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) host_mouse_location, 6485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) host_mouse_location, 6495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ui::EF_IS_SYNTHESIZED, 6505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 0); 6515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return OnEventFromSource(&event); 6525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 6535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 654a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void WindowEventDispatcher::PreDispatchLocatedEvent(Window* target, 655a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) ui::LocatedEvent* event) { 6565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) int flags = event->flags(); 6575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (IsNonClientLocation(target, event->location())) 6585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) flags |= ui::EF_IS_NON_CLIENT; 6595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) event->set_flags(flags); 6605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 6615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (!dispatching_held_event_ && 6625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) (event->IsMouseEvent() || event->IsScrollEvent()) && 6635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) !(event->flags() & ui::EF_IS_SYNTHESIZED)) { 6645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (event->type() != ui::ET_MOUSE_CAPTURE_CHANGED) 6655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) SetLastMouseLocation(window(), event->root_location()); 6665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) synthesize_mouse_move_ = false; 6674e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) } 6682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 6692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 670a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void WindowEventDispatcher::PreDispatchMouseEvent(Window* target, 671a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) ui::MouseEvent* event) { 672f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) client::CursorClient* cursor_client = client::GetCursorClient(window()); 673eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch if (cursor_client && 674eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch !cursor_client->IsMouseEventsEnabled() && 6755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) (event->flags() & ui::EF_IS_SYNTHESIZED)) { 6765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) event->SetHandled(); 6775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return; 6785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 679eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 6805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (IsEventCandidateForHold(*event) && !dispatching_held_event_) { 6815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (move_hold_count_) { 6825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (!(event->flags() & ui::EF_IS_SYNTHESIZED) && 6835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) event->type() != ui::ET_MOUSE_CAPTURE_CHANGED) { 6845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) SetLastMouseLocation(window(), event->root_location()); 6855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 6865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) held_move_event_.reset(new ui::MouseEvent(*event, target, window())); 6875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) event->SetHandled(); 6885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return; 6895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } else { 6905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // We may have a held event for a period between the time move_hold_count_ 6915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // fell to 0 and the DispatchHeldEvents executes. Since we're going to 6925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // dispatch the new event directly below, we can reset the old one. 6935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) held_move_event_.reset(); 6945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 6955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 6965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 6975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const int kMouseButtonFlagMask = ui::EF_LEFT_MOUSE_BUTTON | 6985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ui::EF_MIDDLE_MOUSE_BUTTON | 6995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ui::EF_RIGHT_MOUSE_BUTTON; 7005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) switch (event->type()) { 7012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) case ui::ET_MOUSE_EXITED: 7025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (!target || target == window()) { 703f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) DispatchDetails details = 704f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) DispatchMouseEnterOrExit(*event, ui::ET_MOUSE_EXITED); 7055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (details.dispatcher_destroyed) { 7065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) event->SetHandled(); 7075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return; 7085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 7098bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) mouse_moved_handler_ = NULL; 7102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 7112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) break; 7125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) case ui::ET_MOUSE_MOVED: 71358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) // Send an exit to the current |mouse_moved_handler_| and an enter to 71458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) // |target|. Take care that both us and |target| aren't destroyed during 71558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) // dispatch. 71658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) if (target != mouse_moved_handler_) { 71758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) aura::Window* old_mouse_moved_handler = mouse_moved_handler_; 7185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) WindowTracker live_window; 7195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) live_window.Add(target); 720f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) DispatchDetails details = 721f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) DispatchMouseEnterOrExit(*event, ui::ET_MOUSE_EXITED); 7225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (details.dispatcher_destroyed) { 7235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) event->SetHandled(); 7245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return; 7255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 72658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) // If the |mouse_moved_handler_| changes out from under us, assume a 72758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) // nested message loop ran and we don't need to do anything. 7285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (mouse_moved_handler_ != old_mouse_moved_handler) { 7295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) event->SetHandled(); 7305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return; 7315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 7325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (!live_window.Contains(target) || details.target_destroyed) { 7338bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) mouse_moved_handler_ = NULL; 7345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) event->SetHandled(); 7355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return; 7365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 7375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) live_window.Remove(target); 7385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 7395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) mouse_moved_handler_ = target; 7405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) details = DispatchMouseEnterOrExit(*event, ui::ET_MOUSE_ENTERED); 7415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (details.dispatcher_destroyed || details.target_destroyed) { 7425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) event->SetHandled(); 7435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return; 74458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) } 74558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) } 7465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) break; 7475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) case ui::ET_MOUSE_PRESSED: 7482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Don't set the mouse pressed handler for non client mouse down events. 7492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // These are only sent by Windows and are not always followed with non 7502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // client mouse up events which causes subsequent mouse events to be 7512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // sent to the wrong target. 7522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (!(event->flags() & ui::EF_IS_NON_CLIENT) && !mouse_pressed_handler_) 7535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) mouse_pressed_handler_ = target; 754eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch Env::GetInstance()->set_mouse_button_flags( 755eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch event->flags() & kMouseButtonFlagMask); 7565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) break; 7575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) case ui::ET_MOUSE_RELEASED: 7585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) mouse_pressed_handler_ = NULL; 759eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch Env::GetInstance()->set_mouse_button_flags(event->flags() & 760eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch kMouseButtonFlagMask & ~event->changed_button_flags()); 7615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) break; 7625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) default: 7635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) break; 7645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 7655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 7665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) PreDispatchLocatedEvent(target, event); 7675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 7685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 769a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void WindowEventDispatcher::PreDispatchTouchEvent(Window* target, 770a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) ui::TouchEvent* event) { 7717d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) switch (event->type()) { 7727d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) case ui::ET_TOUCH_PRESSED: 7737d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) touch_ids_down_ |= (1 << event->touch_id()); 7747d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) Env::GetInstance()->set_touch_down(touch_ids_down_ != 0); 7757d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) break; 7767d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 7777d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // Handle ET_TOUCH_CANCELLED only if it has a native event. 7787d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) case ui::ET_TOUCH_CANCELLED: 7797d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) if (!event->HasNativeEvent()) 7807d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) break; 7817d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // fallthrough 7827d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) case ui::ET_TOUCH_RELEASED: 7837d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) touch_ids_down_ = (touch_ids_down_ | (1 << event->touch_id())) ^ 7847d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) (1 << event->touch_id()); 7857d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) Env::GetInstance()->set_touch_down(touch_ids_down_ != 0); 7867d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) break; 7877d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 7885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) case ui::ET_TOUCH_MOVED: 7895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (move_hold_count_ && !dispatching_held_event_) { 7905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) held_move_event_.reset(new ui::TouchEvent(*event, target, window())); 7915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) event->SetHandled(); 7925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return; 7935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 7947d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) break; 7957d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 7965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) default: 7971e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) NOTREACHED(); 7985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) break; 7995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 8005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) PreDispatchLocatedEvent(target, event); 8015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 8025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace aura 804