Chromium Code Reviews| Index: ui/views/controls/menu/menu_event_filter.h |
| diff --git a/ui/views/controls/menu/menu_event_filter.h b/ui/views/controls/menu/menu_event_filter.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..f7e621861be6d678f6e7220f50c5588c07154a2a |
| --- /dev/null |
| +++ b/ui/views/controls/menu/menu_event_filter.h |
| @@ -0,0 +1,73 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef UI_VIEWS_CONTROLS_MENU_MENU_EVENT_FILTER_H_ |
| +#define UI_VIEWS_CONTROLS_MENU_MENU_EVENT_FILTER_H_ |
| + |
| +#include "base/logging.h" |
| +#include "base/macros.h" |
| +#include "base/memory/scoped_ptr.h" |
| +#include "ui/events/event_handler.h" |
| +#include "ui/views/views_export.h" |
| + |
| +namespace aura { |
| +class Window; |
| +} |
| + |
| +namespace ui { |
| +class Accelerator; |
| +} |
| + |
| +namespace views { |
| + |
| +class MenuController; |
| + |
| +// Handles events while a menu is open. |
| +class VIEWS_EXPORT MenuEventFilter : public ui::EventHandler { |
| + public: |
| + // Defines a delegate interface for the MenuEventFilter that can handle |
| + // accelerators on its behalf. |
| + class Delegate { |
| + public: |
| + Delegate() {} |
| + virtual ~Delegate() {} |
| + |
| + // Stores |accelerator| in ui::AcceleratorHistory. |
| + virtual void StoreInHistory(const ui::Accelerator& accelerator) = 0; |
| + |
| + // Returns true if there is an action associated with |accelerator| and |
| + // the menu should be closed before performing the action. |
| + virtual bool ShouldCloseMenuAndRepostAccelerator( |
| + const ui::Accelerator& accelerator) const = 0; |
| + |
| + // Processes |accelerator| immediately. |
| + virtual void ProcessAcceleratorNow(const ui::Accelerator& accelerator) = 0; |
| + }; |
| + |
| + // |menu_controller| should be of the active MenuController, it can't be |
|
oshima
2015/09/02 17:08:21
If this should be one that is always active, why c
afakhry
2015/09/02 18:18:38
Yes I used to do this in an earlier patch, but Pet
oshima
2015/09/02 20:58:54
which patch #?
afakhry
2015/09/03 16:41:42
Patch #21: first comment on this file: https://cod
|
| + // nullptr. If |delegate| is nullptr, the default delegate will be used. |
| + MenuEventFilter(MenuController* menu_controller, |
| + MenuEventFilter::Delegate* delegate); |
| + ~MenuEventFilter() override; |
| + |
| + static void SetMenuEventFilterDelegate(aura::Window* root_window, |
| + MenuEventFilter::Delegate* delegate); |
| + static MenuEventFilter::Delegate* GetMenuEventFilterDelegate( |
| + aura::Window* root_window); |
| + |
| + // ui::EventHandler: |
| + void OnKeyEvent(ui::KeyEvent* event) override; |
| + void OnTouchEvent(ui::TouchEvent* event) override; |
| + |
| + private: |
| + MenuController* menu_controller_; // Not owned. |
| + scoped_ptr<MenuEventFilter::Delegate> default_delegate_; |
| + MenuEventFilter::Delegate* filter_delegate_; // Not owned. |
| + |
| + DISALLOW_COPY_AND_ASSIGN(MenuEventFilter); |
| +}; |
| + |
| +} // namespace views |
| + |
| +#endif // UI_VIEWS_CONTROLS_MENU_MENU_EVENT_FILTER_H_ |