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..c3e309678efd9c6638a42b772e9d0f1779ed2c52 |
| --- /dev/null |
| +++ b/ui/views/controls/menu/menu_event_filter.h |
| @@ -0,0 +1,82 @@ |
| +// 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 aura |
| + |
| +namespace ui { |
| +class Accelerator; |
| +} // namespace ui |
| + |
| +namespace views { |
| + |
| +class MenuController; |
| + |
| +// This will be used as a pre-target-handler whenever a menu is present. It is |
| +// needed to handle the interactions between accelerators and menus. |
| +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() {} |
| + |
| + // When a KeyEvent is received, the corresponding |accelerator| must be |
| + // stored in the |AcceleratorHistory| so that accelerator processing can |
| + // be done properly. |
|
oshima
2015/06/12 19:59:18
can you be more specific about the reason? (If it'
afakhry
2015/06/12 23:50:46
Actually this is specific to ash::AcceleratorContr
|
| + virtual void StoreInHistory(const ui::Accelerator& accelerator) = 0; |
| + |
| + // Processes the given |accelerator| and based on the action associated with |
| + // it, it will either pass it to the accelerator controller to be processed |
|
oshima
2015/06/12 19:59:18
"accelerator controller" is ash specific. you can
afakhry
2015/06/12 23:50:46
Done.
|
| + // now (and returns true - the event's propagation should be stopped), or |
|
oshima
2015/06/12 19:59:19
s/should/will/ ?
afakhry
2015/06/12 23:50:46
It "will". Because the MenuEventFilter will check
|
| + // close the menu and return false (the event propagation should continue so |
| + // the accelerator is handled normally). |
| + virtual bool ProcessAccelerator( |
| + const ui::Accelerator& accelerator, |
| + MenuEventFilter* owner) = 0; |
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(Delegate); |
|
oshima
2015/06/12 19:59:19
you don't need this for pure interface.
afakhry
2015/06/12 23:50:46
Done.
|
| + }; |
| + |
| + MenuEventFilter(); |
| + ~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; |
| + |
| + void SetDelegate(MenuEventFilter::Delegate* delegate); |
| + void ClearDelegate(); |
| + |
| + void CloseMenu() const; |
| + |
| + private: |
| + 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_ |