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.
5 #import "chrome/browser/ui/cocoa/location_bar/manage_passwords_decoration.h"
7 #include "chrome/app/chrome_command_ids.h"
8 #include "chrome/browser/command_updater.h"
9 #include "chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h"
10 #include "chrome/browser/ui/cocoa/passwords/manage_passwords_bubble_cocoa.h"
11 #include "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h"
12 #include "ui/base/l10n/l10n_util_mac.h"
14 // ManagePasswordsIconCocoa
16 ManagePasswordsIconCocoa::ManagePasswordsIconCocoa(
17 ManagePasswordsDecoration* decoration)
18 : decoration_(decoration) {
21 ManagePasswordsIconCocoa::~ManagePasswordsIconCocoa() {
24 void ManagePasswordsIconCocoa::UpdateVisibleUI() {
25 decoration_->UpdateVisibleUI();
28 // ManagePasswordsDecoration
30 ManagePasswordsDecoration::ManagePasswordsDecoration(
31 CommandUpdater* command_updater,
32 LocationBarViewMac* location_bar)
33 : command_updater_(command_updater),
34 location_bar_(location_bar),
35 icon_(new ManagePasswordsIconCocoa(this)) {
39 ManagePasswordsDecoration::~ManagePasswordsDecoration() {
40 if (ManagePasswordsBubbleCocoa::instance())
41 ManagePasswordsBubbleCocoa::instance()->SetIcon(NULL);
44 NSPoint ManagePasswordsDecoration::GetBubblePointInFrame(NSRect frame) {
45 const NSRect draw_frame = GetDrawRectInFrame(frame);
46 return NSMakePoint(NSMidX(draw_frame), NSMaxY(draw_frame));
49 bool ManagePasswordsDecoration::AcceptsMousePress() {
53 bool ManagePasswordsDecoration::OnMousePressed(NSRect frame, NSPoint location) {
54 bool result = ImageDecoration::OnMousePressed(frame, location);
55 if (ManagePasswordsBubbleCocoa::instance())
56 ManagePasswordsBubbleCocoa::instance()->Close();
58 command_updater_->ExecuteCommand(IDC_MANAGE_PASSWORDS_FOR_PAGE);
62 NSString* ManagePasswordsDecoration::GetToolTip() {
63 return icon_->tooltip_text_id()
64 ? l10n_util::GetNSStringWithFixup(icon_->tooltip_text_id())
68 void ManagePasswordsDecoration::OnChange() {
69 // |location_bar_| can be NULL in tests.
71 location_bar_->OnDecorationsChanged();
74 void ManagePasswordsDecoration::UpdateUIState() {
75 if (icon_->state() == password_manager::ui::INACTIVE_STATE) {
78 if (ManagePasswordsBubbleCocoa::instance())
79 ManagePasswordsBubbleCocoa::instance()->Close();
83 SetImage(OmniboxViewMac::ImageForResource(icon_->icon_id()));
86 void ManagePasswordsDecoration::UpdateVisibleUI() {