1// Copyright 2014 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#ifndef CHROME_BROWSER_UI_COCOA_LOCATION_BAR_MANAGE_PASSWORDS_DECORATION_H_ 6#define CHROME_BROWSER_UI_COCOA_LOCATION_BAR_MANAGE_PASSWORDS_DECORATION_H_ 7 8#import <Cocoa/Cocoa.h> 9 10#include "base/compiler_specific.h" 11#include "base/memory/scoped_ptr.h" 12#include "chrome/browser/ui/cocoa/location_bar/image_decoration.h" 13#include "chrome/browser/ui/passwords/manage_passwords_icon.h" 14 15class CommandUpdater; 16class LocationBarViewMac; 17class ManagePasswordsDecoration; 18 19// Cocoa implementation of ManagePasswordsIcon that delegates to 20// ManagePasswordsDecoration. 21class ManagePasswordsIconCocoa : public ManagePasswordsIcon { 22 public: 23 ManagePasswordsIconCocoa(ManagePasswordsDecoration* decoration); 24 virtual ~ManagePasswordsIconCocoa(); 25 virtual void UpdateVisibleUI() OVERRIDE; 26 27 int icon_id() { return icon_id_; } 28 int tooltip_text_id() { return tooltip_text_id_; } 29 30 private: 31 ManagePasswordsDecoration* decoration_; // weak, owns us 32}; 33 34// Manage passwords icon on the right side of the field. This appears when 35// password management is available on the current page. 36class ManagePasswordsDecoration : public ImageDecoration { 37 public: 38 explicit ManagePasswordsDecoration(CommandUpdater* command_updater, 39 LocationBarViewMac* location_bar); 40 virtual ~ManagePasswordsDecoration(); 41 42 // Implement |LocationBarDecoration| 43 virtual bool AcceptsMousePress() OVERRIDE; 44 virtual bool OnMousePressed(NSRect frame, NSPoint location) OVERRIDE; 45 virtual NSString* GetToolTip() OVERRIDE; 46 virtual NSPoint GetBubblePointInFrame(NSRect frame) OVERRIDE; 47 48 // Updates the decoration according to icon state changes. 49 void UpdateVisibleUI(); 50 51 // Accessor for the platform-independent interface. 52 ManagePasswordsIconCocoa* icon() { return icon_.get(); } 53 54 private: 55 // Triggers a redraw after a state change. 56 void OnChange(); 57 58 // Updates child view states. 59 void UpdateUIState(); 60 61 // Shows the manage passwords bubble. 62 CommandUpdater* command_updater_; // Weak, owned by Browser. 63 64 // Displays all the decorations. 65 LocationBarViewMac* location_bar_; // Weak, owns us. 66 67 // The platform-independent interface. 68 scoped_ptr<ManagePasswordsIconCocoa> icon_; 69 70 DISALLOW_COPY_AND_ASSIGN(ManagePasswordsDecoration); 71}; 72 73#endif // CHROME_BROWSER_UI_COCOA_LOCATION_BAR_MANAGE_PASSWORDS_DECORATION_H_ 74