Chromium Code Reviews| 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; | |
|
sky
2012/03/12 15:14:05
It doesn't scale to add a new argument to this int
altimofeev
2012/03/12 15:38:42
I'm not agree with you:
1. Having disposition as a
| |
| 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 void ExecuteCommandWithDisposition(int id, WindowOpenDisposition disposition); | |
| 58 | |
| 50 // An Observer interface implemented by objects that want to be informed when | 59 // An Observer interface implemented by objects that want to be informed when |
| 51 // the state of a particular command ID is modified. | 60 // the state of a particular command ID is modified. |
| 52 class CommandObserver { | 61 class CommandObserver { |
| 53 public: | 62 public: |
| 54 // Notifies the observer that the enabled state has changed for the | 63 // Notifies the observer that the enabled state has changed for the |
| 55 // specified command id. | 64 // specified command id. |
| 56 virtual void EnabledStateChangedForCommand(int id, bool enabled) = 0; | 65 virtual void EnabledStateChangedForCommand(int id, bool enabled) = 0; |
| 57 | 66 |
| 58 protected: | 67 protected: |
| 59 virtual ~CommandObserver(); | 68 virtual ~CommandObserver(); |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 89 | 98 |
| 90 // This is a map of command IDs to states and observer lists | 99 // This is a map of command IDs to states and observer lists |
| 91 typedef base::hash_map<int, Command*> CommandMap; | 100 typedef base::hash_map<int, Command*> CommandMap; |
| 92 CommandMap commands_; | 101 CommandMap commands_; |
| 93 | 102 |
| 94 CommandUpdater(); | 103 CommandUpdater(); |
| 95 DISALLOW_COPY_AND_ASSIGN(CommandUpdater); | 104 DISALLOW_COPY_AND_ASSIGN(CommandUpdater); |
| 96 }; | 105 }; |
| 97 | 106 |
| 98 #endif // CHROME_BROWSER_COMMAND_UPDATER_H_ | 107 #endif // CHROME_BROWSER_COMMAND_UPDATER_H_ |
| OLD | NEW |