Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(536)

Side by Side Diff: chrome/browser/ui/cocoa/browser_window_cocoa.mm

Issue 11416047: Add mac UI for password generation (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: comments and tests Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/cocoa/browser_window_cocoa.h" 5 #include "chrome/browser/ui/cocoa/browser_window_cocoa.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/mac/mac_util.h" 10 #include "base/mac/mac_util.h"
11 #include "base/message_loop.h" 11 #include "base/message_loop.h"
12 #include "base/sys_string_conversions.h" 12 #include "base/sys_string_conversions.h"
13 #include "chrome/app/chrome_command_ids.h" 13 #include "chrome/app/chrome_command_ids.h"
14 #include "chrome/browser/bookmarks/bookmark_utils.h" 14 #include "chrome/browser/bookmarks/bookmark_utils.h"
15 #include "chrome/browser/download/download_shelf.h" 15 #include "chrome/browser/download/download_shelf.h"
16 #include "chrome/browser/extensions/tab_helper.h" 16 #include "chrome/browser/extensions/tab_helper.h"
17 #include "chrome/browser/password_manager/password_manager.h"
17 #include "chrome/browser/prefs/pref_service.h" 18 #include "chrome/browser/prefs/pref_service.h"
18 #include "chrome/browser/profiles/profile.h" 19 #include "chrome/browser/profiles/profile.h"
19 #include "chrome/browser/ui/browser.h" 20 #include "chrome/browser/ui/browser.h"
20 #include "chrome/browser/ui/browser_command_controller.h" 21 #include "chrome/browser/ui/browser_command_controller.h"
21 #include "chrome/browser/ui/browser_commands.h" 22 #include "chrome/browser/ui/browser_commands.h"
22 #include "chrome/browser/ui/browser_list.h" 23 #include "chrome/browser/ui/browser_list.h"
23 #include "chrome/browser/ui/browser_tabstrip.h" 24 #include "chrome/browser/ui/browser_tabstrip.h"
24 #include "chrome/browser/ui/browser_window_state.h" 25 #include "chrome/browser/ui/browser_window_state.h"
25 #import "chrome/browser/ui/cocoa/browser/avatar_button_controller.h" 26 #import "chrome/browser/ui/cocoa/browser/avatar_button_controller.h"
26 #import "chrome/browser/ui/cocoa/browser/avatar_menu_bubble_controller.h" 27 #import "chrome/browser/ui/cocoa/browser/avatar_menu_bubble_controller.h"
27 #import "chrome/browser/ui/cocoa/browser/edit_search_engine_cocoa_controller.h" 28 #import "chrome/browser/ui/cocoa/browser/edit_search_engine_cocoa_controller.h"
29 #import "chrome/browser/ui/cocoa/browser/password_generation_bubble_controller.h "
28 #import "chrome/browser/ui/cocoa/browser_window_controller.h" 30 #import "chrome/browser/ui/cocoa/browser_window_controller.h"
29 #import "chrome/browser/ui/cocoa/browser_window_utils.h" 31 #import "chrome/browser/ui/cocoa/browser_window_utils.h"
30 #import "chrome/browser/ui/cocoa/chrome_event_processing_window.h" 32 #import "chrome/browser/ui/cocoa/chrome_event_processing_window.h"
31 #import "chrome/browser/ui/cocoa/download/download_shelf_controller.h" 33 #import "chrome/browser/ui/cocoa/download/download_shelf_controller.h"
32 #include "chrome/browser/ui/cocoa/find_bar/find_bar_bridge.h" 34 #include "chrome/browser/ui/cocoa/find_bar/find_bar_bridge.h"
33 #import "chrome/browser/ui/cocoa/info_bubble_view.h" 35 #import "chrome/browser/ui/cocoa/info_bubble_view.h"
34 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" 36 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h"
35 #import "chrome/browser/ui/cocoa/nsmenuitem_additions.h" 37 #import "chrome/browser/ui/cocoa/nsmenuitem_additions.h"
36 #include "chrome/browser/ui/cocoa/restart_browser.h" 38 #include "chrome/browser/ui/cocoa/restart_browser.h"
37 #include "chrome/browser/ui/cocoa/status_bubble_mac.h" 39 #include "chrome/browser/ui/cocoa/status_bubble_mac.h"
38 #include "chrome/browser/ui/cocoa/task_manager_mac.h" 40 #include "chrome/browser/ui/cocoa/task_manager_mac.h"
39 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" 41 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h"
40 #import "chrome/browser/ui/cocoa/web_dialog_window_controller.h" 42 #import "chrome/browser/ui/cocoa/web_dialog_window_controller.h"
41 #import "chrome/browser/ui/cocoa/website_settings_bubble_controller.h" 43 #import "chrome/browser/ui/cocoa/website_settings_bubble_controller.h"
42 #include "chrome/browser/ui/page_info_bubble.h" 44 #include "chrome/browser/ui/page_info_bubble.h"
43 #include "chrome/browser/ui/tab_contents/tab_contents.h" 45 #include "chrome/browser/ui/tab_contents/tab_contents.h"
44 #include "chrome/common/chrome_notification_types.h" 46 #include "chrome/common/chrome_notification_types.h"
45 #include "chrome/common/pref_names.h" 47 #include "chrome/common/pref_names.h"
46 #include "content/public/browser/native_web_keyboard_event.h" 48 #include "content/public/browser/native_web_keyboard_event.h"
47 #include "content/public/browser/notification_details.h" 49 #include "content/public/browser/notification_details.h"
48 #include "content/public/browser/notification_source.h" 50 #include "content/public/browser/notification_source.h"
49 #include "content/public/browser/web_contents.h" 51 #include "content/public/browser/web_contents.h"
52 #include "content/public/common/password_form.h"
50 #include "grit/chromium_strings.h" 53 #include "grit/chromium_strings.h"
51 #include "grit/generated_resources.h" 54 #include "grit/generated_resources.h"
52 #include "ui/base/l10n/l10n_util_mac.h" 55 #include "ui/base/l10n/l10n_util_mac.h"
53 #include "ui/gfx/rect.h" 56 #include "ui/gfx/rect.h"
54 57
55 #if defined(ENABLE_ONE_CLICK_SIGNIN) 58 #if defined(ENABLE_ONE_CLICK_SIGNIN)
56 #import "chrome/browser/ui/cocoa/one_click_signin_bubble_controller.h" 59 #import "chrome/browser/ui/cocoa/one_click_signin_bubble_controller.h"
57 #endif 60 #endif
58 61
59 using content::NativeWebKeyboardEvent; 62 using content::NativeWebKeyboardEvent;
(...skipping 13 matching lines...) Expand all
73 }; 76 };
74 typedef NSInteger NSWindowAnimationBehavior; 77 typedef NSInteger NSWindowAnimationBehavior;
75 78
76 @interface NSWindow (LionSDKDeclarations) 79 @interface NSWindow (LionSDKDeclarations)
77 - (NSWindowAnimationBehavior)animationBehavior; 80 - (NSWindowAnimationBehavior)animationBehavior;
78 - (void)setAnimationBehavior:(NSWindowAnimationBehavior)newAnimationBehavior; 81 - (void)setAnimationBehavior:(NSWindowAnimationBehavior)newAnimationBehavior;
79 @end 82 @end
80 83
81 #endif // MAC_OS_X_VERSION_10_7 84 #endif // MAC_OS_X_VERSION_10_7
82 85
86 namespace {
87
88 NSPoint GetPointForBubble(content::WebContents* web_contents,
89 int x_offset,
90 int y_offset) {
91 NSView* view = web_contents->GetNativeView();
92 NSRect bounds = [view bounds];
93 NSPoint point;
94 point.x = NSMinX(bounds) + x_offset;
95 // The view's origin is at the bottom but |rect|'s origin is at the top.
96 point.y = NSMaxY(bounds) - y_offset;
97 point = [view convertPoint:point toView:nil];
98 point = [[view window] convertBaseToScreen:point];
99 return point;
100 }
101
102 } // namespace
103
83 BrowserWindowCocoa::BrowserWindowCocoa(Browser* browser, 104 BrowserWindowCocoa::BrowserWindowCocoa(Browser* browser,
84 BrowserWindowController* controller) 105 BrowserWindowController* controller)
85 : browser_(browser), 106 : browser_(browser),
86 controller_(controller), 107 controller_(controller),
87 confirm_close_factory_(browser), 108 confirm_close_factory_(browser),
88 initial_show_state_(ui::SHOW_STATE_DEFAULT), 109 initial_show_state_(ui::SHOW_STATE_DEFAULT),
89 attention_request_id_(0) { 110 attention_request_id_(0) {
90 111
91 pref_change_registrar_.Init(browser_->profile()->GetPrefs()); 112 pref_change_registrar_.Init(browser_->profile()->GetPrefs());
92 pref_change_registrar_.Add(prefs::kShowBookmarkBar, this); 113 pref_change_registrar_.Add(prefs::kShowBookmarkBar, this);
(...skipping 544 matching lines...) Expand 10 before | Expand all | Expand 10 after
637 // at this point the controller is dead (autoreleased), so 658 // at this point the controller is dead (autoreleased), so
638 // make sure we don't try to reference it any more. 659 // make sure we don't try to reference it any more.
639 } 660 }
640 661
641 NSWindow* BrowserWindowCocoa::window() const { 662 NSWindow* BrowserWindowCocoa::window() const {
642 return [controller_ window]; 663 return [controller_ window];
643 } 664 }
644 665
645 void BrowserWindowCocoa::ShowAvatarBubble(WebContents* web_contents, 666 void BrowserWindowCocoa::ShowAvatarBubble(WebContents* web_contents,
646 const gfx::Rect& rect) { 667 const gfx::Rect& rect) {
647 NSView* view = web_contents->GetNativeView(); 668 NSPoint point = GetPointForBubble(web_contents, rect.right(), rect.bottom());
648 NSRect bounds = [view bounds];
649 NSPoint point;
650 point.x = NSMinX(bounds) + rect.right();
651 // The view's origin is at the bottom but |rect|'s origin is at the top.
652 point.y = NSMaxY(bounds) - rect.bottom();
653 point = [view convertPoint:point toView:nil];
654 point = [[view window] convertBaseToScreen:point];
655 669
656 // |menu| will automatically release itself on close. 670 // |menu| will automatically release itself on close.
657 AvatarMenuBubbleController* menu = 671 AvatarMenuBubbleController* menu =
658 [[AvatarMenuBubbleController alloc] initWithBrowser:browser_ 672 [[AvatarMenuBubbleController alloc] initWithBrowser:browser_
659 anchoredAt:point]; 673 anchoredAt:point];
660 [[menu bubble] setAlignment:info_bubble::kAlignEdgeToAnchorEdge]; 674 [[menu bubble] setAlignment:info_bubble::kAlignEdgeToAnchorEdge];
661 [menu showWindow:nil]; 675 [menu showWindow:nil];
662 } 676 }
663 677
664 void BrowserWindowCocoa::ShowAvatarBubbleFromAvatarButton() { 678 void BrowserWindowCocoa::ShowAvatarBubbleFromAvatarButton() {
665 [[controller_ avatarButtonController] showAvatarBubble]; 679 [[controller_ avatarButtonController] showAvatarBubble];
666 } 680 }
681
682 void BrowserWindowCocoa::ShowPasswordGenerationBubble(
683 const gfx::Rect& rect,
684 const content::PasswordForm& form,
685 autofill::PasswordGenerator* password_generator) {
686 WebContents* web_contents = chrome::GetActiveWebContents(browser_);
687 // We want to point to the middle of the rect instead of the right side.
688 NSPoint point = GetPointForBubble(web_contents,
689 rect.x() + rect.width()/2,
690 rect.bottom());
691
692 PasswordGenerationBubbleController* controller =
693 [[PasswordGenerationBubbleController alloc]
694 initWithWindow:browser_->window()->GetNativeWindow()
695 anchoredAt:point
696 renderViewHost:web_contents->GetRenderViewHost()
697 passwordManager:PasswordManager::FromWebContents(web_contents)
698 usingGenerator:password_generator
699 forForm:form];
700 [controller showWindow:nil];
701 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698