OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 CHROME_BROWSER_COMMAND_UPDATER_H_ | 5 #ifndef CHROME_BROWSER_COMMAND_UPDATER_H_ |
6 #define CHROME_BROWSER_COMMAND_UPDATER_H_ | 6 #define CHROME_BROWSER_COMMAND_UPDATER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/hash_tables.h" | 10 #include "base/hash_tables.h" |
11 #include "webkit/glue/window_open_disposition.h" | |
12 | 11 |
13 //////////////////////////////////////////////////////////////////////////////// | 12 //////////////////////////////////////////////////////////////////////////////// |
14 // | 13 // |
15 // CommandUpdater class | 14 // CommandUpdater class |
16 // | 15 // |
17 // This object manages the enabled state of a set of commands. Observers | 16 // This object manages the enabled state of a set of commands. Observers |
18 // register to listen to changes in this state so they can update their | 17 // register to listen to changes in this state so they can update their |
19 // presentation. | 18 // presentation. |
20 // | 19 // |
21 class CommandUpdater { | 20 class CommandUpdater { |
22 public: | 21 public: |
23 // A Delegate object implements this interface so that it can execute commands | 22 // A Delegate object implements this interface so that it can execute commands |
24 // when needed. | 23 // when needed. |
25 class CommandUpdaterDelegate { | 24 class CommandUpdaterDelegate { |
26 public: | 25 public: |
27 // Performs the action associated with the command with the specified ID and | 26 // Perform the action associated with the command with the specified ID. |
28 // using the given disposition. | 27 virtual void ExecuteCommand(int id) = 0; |
29 virtual void ExecuteCommandWithDisposition( | |
30 int id, | |
31 WindowOpenDisposition disposition) = 0; | |
32 | 28 |
33 protected: | 29 protected: |
34 virtual ~CommandUpdaterDelegate(); | 30 virtual ~CommandUpdaterDelegate(); |
35 }; | 31 }; |
36 | 32 |
37 // Create a CommandUpdater with a CommandUpdaterDelegate to handle execution | 33 // Create a CommandUpdater with a CommandUpdaterDelegate to handle execution |
38 // of specific commands. | 34 // of specific commands. |
39 explicit CommandUpdater(CommandUpdaterDelegate* handler); | 35 explicit CommandUpdater(CommandUpdaterDelegate* handler); |
40 virtual ~CommandUpdater(); | 36 virtual ~CommandUpdater(); |
41 | 37 |
42 // Returns true if the specified command ID is supported. | 38 // Returns true if the specified command ID is supported. |
43 bool SupportsCommand(int id) const; | 39 bool SupportsCommand(int id) const; |
44 | 40 |
45 // Returns true if the specified command ID is enabled. The command ID must be | 41 // Returns true if the specified command ID is enabled. The command ID must be |
46 // supported by this updater. | 42 // supported by this updater. |
47 bool IsCommandEnabled(int id) const; | 43 bool IsCommandEnabled(int id) const; |
48 | 44 |
49 // Performs the action associated with this command ID using CURRENT_TAB | 45 // Performs the action associated with this command ID. |
50 // disposition. | |
51 // TODO(beng): get rid of this since it's effectively just a pass-thru and the | 46 // TODO(beng): get rid of this since it's effectively just a pass-thru and the |
52 // call sites would be better off using more well defined delegate interfaces. | 47 // call sites would be better off using more well defined delegate interfaces. |
53 void ExecuteCommand(int id); | 48 void ExecuteCommand(int id); |
54 | 49 |
55 // Performs the action associated with this command ID using the given | |
56 // disposition. | |
57 // TODO(altimofeev): refactor the interface to provide more flexible and | |
58 // explicit way for passing command specific arguments. See | |
59 // NotificationDetails class for the possible implementation ideas. | |
60 void ExecuteCommandWithDisposition(int id, WindowOpenDisposition disposition); | |
61 | |
62 // An Observer interface implemented by objects that want to be informed when | 50 // An Observer interface implemented by objects that want to be informed when |
63 // the state of a particular command ID is modified. | 51 // the state of a particular command ID is modified. |
64 class CommandObserver { | 52 class CommandObserver { |
65 public: | 53 public: |
66 // Notifies the observer that the enabled state has changed for the | 54 // Notifies the observer that the enabled state has changed for the |
67 // specified command id. | 55 // specified command id. |
68 virtual void EnabledStateChangedForCommand(int id, bool enabled) = 0; | 56 virtual void EnabledStateChangedForCommand(int id, bool enabled) = 0; |
69 | 57 |
70 protected: | 58 protected: |
71 virtual ~CommandObserver(); | 59 virtual ~CommandObserver(); |
(...skipping 29 matching lines...) Expand all Loading... |
101 | 89 |
102 // This is a map of command IDs to states and observer lists | 90 // This is a map of command IDs to states and observer lists |
103 typedef base::hash_map<int, Command*> CommandMap; | 91 typedef base::hash_map<int, Command*> CommandMap; |
104 CommandMap commands_; | 92 CommandMap commands_; |
105 | 93 |
106 CommandUpdater(); | 94 CommandUpdater(); |
107 DISALLOW_COPY_AND_ASSIGN(CommandUpdater); | 95 DISALLOW_COPY_AND_ASSIGN(CommandUpdater); |
108 }; | 96 }; |
109 | 97 |
110 #endif // CHROME_BROWSER_COMMAND_UPDATER_H_ | 98 #endif // CHROME_BROWSER_COMMAND_UPDATER_H_ |
OLD | NEW |