OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #import <Cocoa/Cocoa.h> |
| 6 |
| 7 #include "chrome/browser/command_updater.h" |
| 8 |
| 9 @protocol CommandObserverProtocol; |
| 10 |
| 11 // A C++ bridge class that handles listening for updates to commands and |
| 12 // passing them back to an object that supports the protocol delcared below. |
| 13 // The observer will create one of these bridges, call ObserveCommand() on the |
| 14 // command ids it cares about, and then wait for update notifications, |
| 15 // delivered via -enabledStateChangedForCommand:enabled:. Destroying this |
| 16 // bridge will handle automatically unregistering for updates, so there's no |
| 17 // need to do that manually. |
| 18 |
| 19 class CommandObserverBridge : public CommandUpdater::CommandObserver { |
| 20 public: |
| 21 CommandObserverBridge(id<CommandObserverProtocol> observer, |
| 22 CommandUpdater* commands); |
| 23 virtual ~CommandObserverBridge(); |
| 24 |
| 25 // Register for updates about |command|. |
| 26 void ObserveCommand(int command); |
| 27 |
| 28 protected: |
| 29 // Overridden from CommandUpdater::CommandObserver |
| 30 virtual void EnabledStateChangedForCommand(int command, bool enabled); |
| 31 |
| 32 private: |
| 33 id<CommandObserverProtocol> observer_; // weak, owns me |
| 34 CommandUpdater* commands_; // weak |
| 35 }; |
| 36 |
| 37 // Implemented by the observing Objective-C object, called when there is a |
| 38 // state change for the given command. |
| 39 @protocol CommandObserverProtocol |
| 40 - (void)enabledStateChangedForCommand:(NSInteger)command enabled:(BOOL)enabled; |
| 41 @end |
OLD | NEW |