Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(289)

Side by Side Diff: ash/launcher/launcher_delegate.h

Issue 22429004: Refactor LauncherDelegate (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix bugs Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef ASH_LAUNCHER_LAUNCHER_DELEGATE_H_ 5 #ifndef ASH_LAUNCHER_LAUNCHER_DELEGATE_H_
6 #define ASH_LAUNCHER_LAUNCHER_DELEGATE_H_ 6 #define ASH_LAUNCHER_LAUNCHER_DELEGATE_H_
7 7
8 #include "ash/ash_export.h" 8 #include "ash/ash_export.h"
9 #include "ash/launcher/launcher_types.h" 9 #include "ash/launcher/launcher_types.h"
10 #include "base/strings/string16.h"
11 #include "ui/base/models/simple_menu_model.h"
12
13 namespace aura {
14 class RootWindow;
15 }
16
17 namespace ui {
18 class Event;
19 }
20 10
21 namespace ash { 11 namespace ash {
22 class Launcher; 12 class Launcher;
23 13 class LauncherItemDelegate;
24 // A special menu model which keeps track of an "active" menu item.
25 class ASH_EXPORT LauncherMenuModel : public ui::SimpleMenuModel {
26 public:
27 explicit LauncherMenuModel(ui::SimpleMenuModel::Delegate* delegate)
28 : ui::SimpleMenuModel(delegate) {}
29
30 // Returns |true| when the given |command_id| is active and needs to be drawn
31 // in a special state.
32 virtual bool IsCommandActive(int command_id) const = 0;
33
34 private:
35 DISALLOW_COPY_AND_ASSIGN(LauncherMenuModel);
36 };
37 14
38 // Delegate for the Launcher. 15 // Delegate for the Launcher.
39 class ASH_EXPORT LauncherDelegate { 16 class ASH_EXPORT LauncherDelegate {
40 public: 17 public:
41 // Launcher owns the delegate. 18 // LauncherDelegateProxy owns the delegate.
42 virtual ~LauncherDelegate() {} 19 virtual ~LauncherDelegate();
43
44 // Invoked when the user clicks on a window entry in the launcher.
45 // |event| is the click event. The |event| is dispatched by a view
46 // and has an instance of |views::View| as the event target
47 // but not |aura::Window|. If the |event| is of type KeyEvent, it is assumed
48 // that this was triggered by keyboard action (Alt+<number>) and special
49 // handling might happen (PerApp launcher).
50 virtual void ItemSelected(const LauncherItem& item,
51 const ui::Event& event) = 0;
52
53 // Returns the title to display for the specified launcher item.
54 virtual base::string16 GetTitle(const LauncherItem& item) = 0;
55
56 // Returns the context menumodel for the specified item on
57 // |root_window|. Return NULL if there should be no context
58 // menu. The caller takes ownership of the returned model.
59 virtual ui::MenuModel* CreateContextMenu(const LauncherItem& item,
60 aura::RootWindow* root_window) = 0;
61
62 // Returns the application menu model for the specified item. There are three
63 // possible return values:
64 // - A return of NULL indicates that no menu is wanted for this item.
65 // - A return of a menu with one item means that only the name of the
66 // application/item was added and there are no active applications.
67 // Note: This is useful for hover menus which also show context help.
68 // - A list containing the title and the active list of items.
69 // The caller takes ownership of the returned model.
70 // |event_flags| specifies the flags of the event which triggered this menu.
71 virtual LauncherMenuModel* CreateApplicationMenu(
72 const LauncherItem& item,
73 int event_flags) = 0;
74 20
75 // Returns the id of the item associated with the specified window, or 0 if 21 // Returns the id of the item associated with the specified window, or 0 if
76 // there isn't one. 22 // there isn't one.
77 virtual LauncherID GetIDByWindow(aura::Window* window) = 0; 23 virtual LauncherID GetIDByWindow(aura::Window* window) = 0;
78 24
79 // Whether the given launcher item is draggable.
80 virtual bool IsDraggable(const LauncherItem& item) = 0;
81
82 // Returns true if a tooltip should be shown for the item.
83 virtual bool ShouldShowTooltip(const LauncherItem& item) = 0;
84
85 // Callback used to allow delegate to perform initialization actions that 25 // Callback used to allow delegate to perform initialization actions that
86 // depend on the Launcher being in a known state. 26 // depend on the Launcher being in a known state.
87 virtual void OnLauncherCreated(Launcher* launcher) = 0; 27 virtual void OnLauncherCreated(Launcher* launcher) = 0;
88 28
89 // Callback used to inform the delegate that a specific launcher no longer 29 // Callback used to inform the delegate that a specific launcher no longer
90 // exists. 30 // exists.
91 virtual void OnLauncherDestroyed(Launcher* launcher) = 0; 31 virtual void OnLauncherDestroyed(Launcher* launcher) = 0;
92 32
93 // True if the running launcher is the per application launcher.
94 virtual bool IsPerAppLauncher() = 0;
95
96 // Get the launcher ID from an application ID. 33 // Get the launcher ID from an application ID.
97 virtual LauncherID GetLauncherIDForAppID(const std::string& app_id) = 0; 34 virtual LauncherID GetLauncherIDForAppID(const std::string& app_id) = 0;
98 35
99 // Pins an app with |app_id| to launcher. A running instance will get pinned. 36 // Pins an app with |app_id| to launcher. A running instance will get pinned.
100 // In case there is no running instance a new launcher item is created and 37 // In case there is no running instance a new launcher item is created and
101 // pinned. 38 // pinned.
102 virtual void PinAppWithID(const std::string& app_id) = 0; 39 virtual void PinAppWithID(const std::string& app_id) = 0;
103 40
104 // Check if the app with |app_id_| is pinned to the launcher. 41 // Check if the app with |app_id_| is pinned to the launcher.
105 virtual bool IsAppPinned(const std::string& app_id) = 0; 42 virtual bool IsAppPinned(const std::string& app_id) = 0;
106 43
107 // Unpins any app item(s) whose id is |app_id|. The new launcher will collect 44 // Unpins any app item(s) whose id is |app_id|. The new launcher will collect
108 // all items under one item, the old launcher might have multiple items. 45 // all items under one item, the old launcher might have multiple items.
109 virtual void UnpinAppsWithID(const std::string& app_id) = 0; 46 virtual void UnpinAppsWithID(const std::string& app_id) = 0;
47
48 // Returns NULL if LauncherDelegate doesn't handle |item|.
49 virtual LauncherItemDelegate* GetLauncherItemDelegate(
50 const LauncherItem& item) = 0;
51
52 // True if the running launcher is the per application launcher.
53 virtual bool IsPerAppLauncher();
54
55 // Returns true if LauncherDelegate can pin apps.
56 virtual bool CanPin() const { return false; }
110 }; 57 };
111 58
112 } // namespace ash 59 } // namespace ash
113 60
114 #endif // ASH_LAUNCHER_LAUNCHER_DELEGATE_H_ 61 #endif // ASH_LAUNCHER_LAUNCHER_DELEGATE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698