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

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: Sync 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/download/download_shelf.h" 14 #include "chrome/browser/download/download_shelf.h"
15 #include "chrome/browser/extensions/tab_helper.h" 15 #include "chrome/browser/extensions/tab_helper.h"
16 #include "chrome/browser/password_manager/password_manager.h"
16 #include "chrome/browser/prefs/pref_service.h" 17 #include "chrome/browser/prefs/pref_service.h"
17 #include "chrome/browser/profiles/profile.h" 18 #include "chrome/browser/profiles/profile.h"
18 #include "chrome/browser/ui/bookmarks/bookmark_utils.h" 19 #include "chrome/browser/ui/bookmarks/bookmark_utils.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/common/chrome_notification_types.h" 45 #include "chrome/common/chrome_notification_types.h"
44 #include "chrome/common/pref_names.h" 46 #include "chrome/common/pref_names.h"
45 #include "content/public/browser/native_web_keyboard_event.h" 47 #include "content/public/browser/native_web_keyboard_event.h"
46 #include "content/public/browser/notification_details.h" 48 #include "content/public/browser/notification_details.h"
47 #include "content/public/browser/notification_source.h" 49 #include "content/public/browser/notification_source.h"
48 #include "content/public/browser/web_contents.h" 50 #include "content/public/browser/web_contents.h"
51 #include "content/public/common/password_form.h"
49 #include "grit/chromium_strings.h" 52 #include "grit/chromium_strings.h"
50 #include "grit/generated_resources.h" 53 #include "grit/generated_resources.h"
51 #include "ui/base/l10n/l10n_util_mac.h" 54 #include "ui/base/l10n/l10n_util_mac.h"
52 #include "ui/gfx/rect.h" 55 #include "ui/gfx/rect.h"
53 56
54 #if defined(ENABLE_ONE_CLICK_SIGNIN) 57 #if defined(ENABLE_ONE_CLICK_SIGNIN)
55 #import "chrome/browser/ui/cocoa/one_click_signin_bubble_controller.h" 58 #import "chrome/browser/ui/cocoa/one_click_signin_bubble_controller.h"
56 #endif 59 #endif
57 60
58 using content::NativeWebKeyboardEvent; 61 using content::NativeWebKeyboardEvent;
(...skipping 13 matching lines...) Expand all
72 }; 75 };
73 typedef NSInteger NSWindowAnimationBehavior; 76 typedef NSInteger NSWindowAnimationBehavior;
74 77
75 @interface NSWindow (LionSDKDeclarations) 78 @interface NSWindow (LionSDKDeclarations)
76 - (NSWindowAnimationBehavior)animationBehavior; 79 - (NSWindowAnimationBehavior)animationBehavior;
77 - (void)setAnimationBehavior:(NSWindowAnimationBehavior)newAnimationBehavior; 80 - (void)setAnimationBehavior:(NSWindowAnimationBehavior)newAnimationBehavior;
78 @end 81 @end
79 82
80 #endif // MAC_OS_X_VERSION_10_7 83 #endif // MAC_OS_X_VERSION_10_7
81 84
85 namespace {
86
87 NSPoint GetPointForBubble(content::WebContents* web_contents,
88 int x_offset,
89 int y_offset) {
90 NSView* view = web_contents->GetNativeView();
91 NSRect bounds = [view bounds];
92 NSPoint point;
93 point.x = NSMinX(bounds) + x_offset;
94 // The view's origin is at the bottom but |rect|'s origin is at the top.
95 point.y = NSMaxY(bounds) - y_offset;
96 point = [view convertPoint:point toView:nil];
97 point = [[view window] convertBaseToScreen:point];
98 return point;
99 }
100
101 } // namespace
102
82 BrowserWindowCocoa::BrowserWindowCocoa(Browser* browser, 103 BrowserWindowCocoa::BrowserWindowCocoa(Browser* browser,
83 BrowserWindowController* controller) 104 BrowserWindowController* controller)
84 : browser_(browser), 105 : browser_(browser),
85 controller_(controller), 106 controller_(controller),
86 confirm_close_factory_(browser), 107 confirm_close_factory_(browser),
87 initial_show_state_(ui::SHOW_STATE_DEFAULT), 108 initial_show_state_(ui::SHOW_STATE_DEFAULT),
88 attention_request_id_(0) { 109 attention_request_id_(0) {
89 110
90 gfx::Rect bounds; 111 gfx::Rect bounds;
91 chrome::GetSavedWindowBoundsAndShowState(browser_, 112 chrome::GetSavedWindowBoundsAndShowState(browser_,
(...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after
630 // at this point the controller is dead (autoreleased), so 651 // at this point the controller is dead (autoreleased), so
631 // make sure we don't try to reference it any more. 652 // make sure we don't try to reference it any more.
632 } 653 }
633 654
634 NSWindow* BrowserWindowCocoa::window() const { 655 NSWindow* BrowserWindowCocoa::window() const {
635 return [controller_ window]; 656 return [controller_ window];
636 } 657 }
637 658
638 void BrowserWindowCocoa::ShowAvatarBubble(WebContents* web_contents, 659 void BrowserWindowCocoa::ShowAvatarBubble(WebContents* web_contents,
639 const gfx::Rect& rect) { 660 const gfx::Rect& rect) {
640 NSView* view = web_contents->GetNativeView(); 661 NSPoint point = GetPointForBubble(web_contents, rect.right(), rect.bottom());
641 NSRect bounds = [view bounds];
642 NSPoint point;
643 point.x = NSMinX(bounds) + rect.right();
644 // The view's origin is at the bottom but |rect|'s origin is at the top.
645 point.y = NSMaxY(bounds) - rect.bottom();
646 point = [view convertPoint:point toView:nil];
647 point = [[view window] convertBaseToScreen:point];
648 662
649 // |menu| will automatically release itself on close. 663 // |menu| will automatically release itself on close.
650 AvatarMenuBubbleController* menu = 664 AvatarMenuBubbleController* menu =
651 [[AvatarMenuBubbleController alloc] initWithBrowser:browser_ 665 [[AvatarMenuBubbleController alloc] initWithBrowser:browser_
652 anchoredAt:point]; 666 anchoredAt:point];
653 [[menu bubble] setAlignment:info_bubble::kAlignEdgeToAnchorEdge]; 667 [[menu bubble] setAlignment:info_bubble::kAlignEdgeToAnchorEdge];
654 [menu showWindow:nil]; 668 [menu showWindow:nil];
655 } 669 }
656 670
657 void BrowserWindowCocoa::ShowAvatarBubbleFromAvatarButton() { 671 void BrowserWindowCocoa::ShowAvatarBubbleFromAvatarButton() {
658 [[controller_ avatarButtonController] showAvatarBubble]; 672 [[controller_ avatarButtonController] showAvatarBubble];
659 } 673 }
674
675 void BrowserWindowCocoa::ShowPasswordGenerationBubble(
676 const gfx::Rect& rect,
677 const content::PasswordForm& form,
678 autofill::PasswordGenerator* password_generator) {
679 WebContents* web_contents = chrome::GetActiveWebContents(browser_);
680 // We want to point to the middle of the rect instead of the right side.
681 NSPoint point = GetPointForBubble(web_contents,
682 rect.x() + rect.width()/2,
683 rect.bottom());
684
685 PasswordGenerationBubbleController* controller =
686 [[PasswordGenerationBubbleController alloc]
687 initWithWindow:browser_->window()->GetNativeWindow()
688 anchoredAt:point
689 renderViewHost:web_contents->GetRenderViewHost()
690 passwordManager:PasswordManager::FromWebContents(web_contents)
691 usingGenerator:password_generator
692 forForm:form];
693 [controller showWindow:nil];
694 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698