15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 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) 5d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#ifndef UI_EVENTS_EVENT_HANDLER_H_ 6d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#define UI_EVENTS_EVENT_HANDLER_H_ 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 82a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include <stack> 95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <vector> 105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/basictypes.h" 12d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#include "ui/events/event_constants.h" 1368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)#include "ui/events/events_export.h" 145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace ui { 165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class CancelModeEvent; 182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class Event; 192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class EventDispatcher; 202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class EventTarget; 215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class GestureEvent; 225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class KeyEvent; 235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class MouseEvent; 245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class ScrollEvent; 255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class TouchEvent; 265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Dispatches events to appropriate targets. The default implementations of 282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// all of the specific handlers (e.g. OnKeyEvent, OnMouseEvent) do nothing. 2968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)class EVENTS_EXPORT EventHandler { 305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EventHandler(); 322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual ~EventHandler(); 332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // This is called for all events. The default implementation routes the event 352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // to one of the event-specific callbacks (OnKeyEvent, OnMouseEvent etc.). If 362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // this is overridden, then normally, the override should chain into the 372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // default implementation for un-handled events. 382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual void OnEvent(Event* event); 392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual void OnKeyEvent(KeyEvent* event); 412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual void OnMouseEvent(MouseEvent* event); 432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual void OnScrollEvent(ScrollEvent* event); 452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual void OnTouchEvent(TouchEvent* event); 475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual void OnGestureEvent(GestureEvent* event); 495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual void OnCancelMode(CancelModeEvent* event); 515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) private: 532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) friend class EventDispatcher; 545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // EventDispatcher pushes itself on the top of this stack while dispatching 562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // events to this then pops itself off when done. 572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) std::stack<EventDispatcher*> dispatchers_; 585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(EventHandler); 605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)typedef std::vector<EventHandler*> EventHandlerList; 635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace ui 655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 66d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#endif // UI_EVENTS_EVENT_HANDLER_H_ 67