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