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