1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- // Copyright (c) 2021 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 ASH_APP_LIST_VIEWS_APPS_GRID_CONTEXT_MENU_H_
- #define ASH_APP_LIST_VIEWS_APPS_GRID_CONTEXT_MENU_H_
- #include <memory>
- #include "ash/ash_export.h"
- #include "ui/base/models/simple_menu_model.h"
- #include "ui/views/context_menu_controller.h"
- namespace views {
- class MenuItemView;
- class MenuModelAdapter;
- class MenuRunner;
- } // namespace views
- namespace ash {
- // This class is the context menu controller used by AppsGridView, responsible
- // for building, running the menu and executing the commands.
- class ASH_EXPORT AppsGridContextMenu : public ui::SimpleMenuModel::Delegate,
- public views::ContextMenuController {
- public:
- AppsGridContextMenu();
- AppsGridContextMenu(const AppsGridContextMenu&) = delete;
- AppsGridContextMenu& operator=(const AppsGridContextMenu&) = delete;
- ~AppsGridContextMenu() override;
- // Returns true if the apps grid context menu is showing.
- bool IsMenuShowing() const;
- // Closes the context menu if it's showning.
- void Cancel();
- // ui::SimpleMenuModel::Delegate:
- void ExecuteCommand(int command_id, int event_flags) override;
- void set_owner_touch_dragging(bool touch_dragging) {
- owner_touch_dragging_ = touch_dragging;
- }
- views::MenuItemView* root_menu_item_view() const {
- return root_menu_item_view_;
- }
- private:
- // views::ContextMenuController:
- void ShowContextMenuForViewImpl(views::View* source,
- const gfx::Point& point,
- ui::MenuSourceType source_type) override;
- // Builds and saves a SimpleMenuModel to `context_menu_model_`;
- void BuildMenuModel();
- // Called when the context menu is closed. Used as a callback for
- // `menu_model_adapter_`.
- void OnMenuClosed();
- // The context menu model and its adapter for AppsGridView.
- std::unique_ptr<ui::SimpleMenuModel> context_menu_model_;
- std::unique_ptr<views::MenuModelAdapter> menu_model_adapter_;
- // The menu runner that is responsible to run the menu.
- std::unique_ptr<views::MenuRunner> menu_runner_;
- // The root menu item view of `context_menu_model_`. Cached for testing.
- views::MenuItemView* root_menu_item_view_ = nullptr;
- // Whether the owner view is currently touch dragging, in which case touch
- // events will be forwarded from the context menu to the owner view (so the
- // view can transition from showing a context menu to item drag).
- bool owner_touch_dragging_ = false;
- };
- } // namespace ash
- #endif // ASH_APP_LIST_VIEWS_APPS_GRID_CONTEXT_MENU_H_
|