Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / cocoa / location_bar / manage_passwords_decoration.mm
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 #import "chrome/browser/ui/cocoa/location_bar/manage_passwords_decoration.h"
6
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 "ui/base/l10n/l10n_util_mac.h"
11
12 // ManagePasswordsIconCocoa
13
14 ManagePasswordsIconCocoa::ManagePasswordsIconCocoa(
15     ManagePasswordsDecoration* decoration)
16     : decoration_(decoration) {
17 }
18
19 ManagePasswordsIconCocoa::~ManagePasswordsIconCocoa() {
20 }
21
22 void ManagePasswordsIconCocoa::UpdateVisibleUI() {
23   decoration_->UpdateVisibleUI();
24 }
25
26 // ManagePasswordsDecoration
27
28 ManagePasswordsDecoration::ManagePasswordsDecoration(
29     CommandUpdater* command_updater)
30     : command_updater_(command_updater),
31       icon_(new ManagePasswordsIconCocoa(this)) {
32   UpdateVisibleUI();
33 }
34
35 ManagePasswordsDecoration::~ManagePasswordsDecoration() {}
36
37 NSPoint ManagePasswordsDecoration::GetBubblePointInFrame(NSRect frame) {
38   const NSRect draw_frame = GetDrawRectInFrame(frame);
39   return NSMakePoint(NSMidX(draw_frame), NSMaxY(draw_frame));
40 }
41
42 bool ManagePasswordsDecoration::AcceptsMousePress() {
43   return true;
44 }
45
46 bool ManagePasswordsDecoration::OnMousePressed(NSRect frame, NSPoint location) {
47   command_updater_->ExecuteCommand(IDC_MANAGE_PASSWORDS_FOR_PAGE);
48   return true;
49 }
50
51 NSString* ManagePasswordsDecoration::GetToolTip() {
52   return icon_->tooltip_text_id()
53              ? l10n_util::GetNSStringWithFixup(icon_->tooltip_text_id())
54              : nil;
55 }
56
57 void ManagePasswordsDecoration::UpdateVisibleUI() {
58   if (icon_->state() == password_manager::ui::INACTIVE_STATE) {
59     SetVisible(false);
60     SetImage(nil);
61     // TODO(dconnelly): Hide the bubble once it is implemented.
62     return;
63   }
64   SetVisible(true);
65   SetImage(OmniboxViewMac::ImageForResource(icon_->icon_id()));
66 }