OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/views/passwords/manage_passwords_bubble_view.h" | 5 #include "chrome/browser/ui/views/passwords/manage_passwords_bubble_view.h" |
6 | 6 |
7 #include "chrome/browser/chrome_notification_types.h" | 7 #include "chrome/browser/chrome_notification_types.h" |
8 #include "chrome/browser/ui/browser.h" | 8 #include "chrome/browser/ui/browser.h" |
9 #include "chrome/browser/ui/browser_finder.h" | 9 #include "chrome/browser/ui/browser_finder.h" |
10 #include "chrome/browser/ui/fullscreen/fullscreen_controller.h" | 10 #include "chrome/browser/ui/fullscreen/fullscreen_controller.h" |
11 #include "chrome/browser/ui/passwords/manage_passwords_bubble_model.h" | 11 #include "chrome/browser/ui/passwords/manage_passwords_bubble_model.h" |
12 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller.h" | 12 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller.h" |
13 #include "chrome/browser/ui/passwords/save_password_refusal_combobox_model.h" | 13 #include "chrome/browser/ui/passwords/save_password_refusal_combobox_model.h" |
14 #include "chrome/browser/ui/views/frame/browser_view.h" | 14 #include "chrome/browser/ui/views/frame/browser_view.h" |
15 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" | 15 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" |
16 #include "chrome/browser/ui/views/passwords/credentials_item_view.h" | 16 #include "chrome/browser/ui/views/passwords/credentials_item_view.h" |
17 #include "chrome/browser/ui/views/passwords/manage_password_items_view.h" | 17 #include "chrome/browser/ui/views/passwords/manage_password_items_view.h" |
18 #include "chrome/browser/ui/views/passwords/manage_passwords_icon_view.h" | 18 #include "chrome/browser/ui/views/passwords/manage_passwords_icon_view.h" |
19 #include "chrome/grit/generated_resources.h" | 19 #include "chrome/grit/generated_resources.h" |
20 #include "content/public/browser/notification_source.h" | 20 #include "content/public/browser/notification_source.h" |
21 #include "content/public/browser/render_view_host.h" | 21 #include "content/public/browser/render_view_host.h" |
22 #include "content/public/browser/web_contents.h" | 22 #include "content/public/browser/web_contents.h" |
23 #include "ui/aura/window.h" | |
24 #include "ui/base/l10n/l10n_util.h" | 23 #include "ui/base/l10n/l10n_util.h" |
25 #include "ui/base/resource/resource_bundle.h" | 24 #include "ui/base/resource/resource_bundle.h" |
26 #include "ui/views/controls/button/blue_button.h" | 25 #include "ui/views/controls/button/blue_button.h" |
27 #include "ui/views/controls/button/label_button.h" | 26 #include "ui/views/controls/button/label_button.h" |
28 #include "ui/views/controls/combobox/combobox.h" | 27 #include "ui/views/controls/combobox/combobox.h" |
29 #include "ui/views/controls/combobox/combobox_listener.h" | 28 #include "ui/views/controls/combobox/combobox_listener.h" |
30 #include "ui/views/controls/link.h" | 29 #include "ui/views/controls/link.h" |
31 #include "ui/views/controls/link_listener.h" | 30 #include "ui/views/controls/link_listener.h" |
32 #include "ui/views/controls/separator.h" | 31 #include "ui/views/controls/separator.h" |
33 #include "ui/views/controls/styled_label.h" | 32 #include "ui/views/controls/styled_label.h" |
34 #include "ui/views/controls/styled_label_listener.h" | 33 #include "ui/views/controls/styled_label_listener.h" |
| 34 #include "ui/views/event_monitor.h" |
35 #include "ui/views/layout/fill_layout.h" | 35 #include "ui/views/layout/fill_layout.h" |
36 #include "ui/views/layout/grid_layout.h" | 36 #include "ui/views/layout/grid_layout.h" |
37 #include "ui/views/layout/layout_constants.h" | 37 #include "ui/views/layout/layout_constants.h" |
38 #include "ui/views/widget/widget.h" | 38 #include "ui/views/widget/widget.h" |
39 | 39 |
40 | 40 |
41 // Helpers -------------------------------------------------------------------- | 41 // Helpers -------------------------------------------------------------------- |
42 | 42 |
43 namespace { | 43 namespace { |
44 | 44 |
(...skipping 863 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
908 } | 908 } |
909 | 909 |
910 // ManagePasswordsBubbleView::WebContentMouseHandler -------------------------- | 910 // ManagePasswordsBubbleView::WebContentMouseHandler -------------------------- |
911 | 911 |
912 // The class listens for WebContentsView events and notifies the bubble if the | 912 // The class listens for WebContentsView events and notifies the bubble if the |
913 // view was clicked on or received keystrokes. | 913 // view was clicked on or received keystrokes. |
914 class ManagePasswordsBubbleView::WebContentMouseHandler | 914 class ManagePasswordsBubbleView::WebContentMouseHandler |
915 : public ui::EventHandler { | 915 : public ui::EventHandler { |
916 public: | 916 public: |
917 explicit WebContentMouseHandler(ManagePasswordsBubbleView* bubble); | 917 explicit WebContentMouseHandler(ManagePasswordsBubbleView* bubble); |
918 ~WebContentMouseHandler() override; | |
919 | 918 |
920 void OnKeyEvent(ui::KeyEvent* event) override; | 919 void OnKeyEvent(ui::KeyEvent* event) override; |
921 void OnMouseEvent(ui::MouseEvent* event) override; | 920 void OnMouseEvent(ui::MouseEvent* event) override; |
922 | 921 |
923 private: | 922 private: |
924 aura::Window* GetWebContentsWindow(); | |
925 | |
926 ManagePasswordsBubbleView* bubble_; | 923 ManagePasswordsBubbleView* bubble_; |
| 924 scoped_ptr<views::EventMonitor> event_monitor_; |
927 | 925 |
928 DISALLOW_COPY_AND_ASSIGN(WebContentMouseHandler); | 926 DISALLOW_COPY_AND_ASSIGN(WebContentMouseHandler); |
929 }; | 927 }; |
930 | 928 |
931 ManagePasswordsBubbleView::WebContentMouseHandler::WebContentMouseHandler( | 929 ManagePasswordsBubbleView::WebContentMouseHandler::WebContentMouseHandler( |
932 ManagePasswordsBubbleView* bubble) | 930 ManagePasswordsBubbleView* bubble) |
933 : bubble_(bubble) { | 931 : bubble_(bubble) { |
934 GetWebContentsWindow()->AddPreTargetHandler(this); | 932 content::WebContents* web_contents = bubble_->web_contents(); |
935 } | 933 DCHECK(web_contents); |
936 | 934 event_monitor_ = views::EventMonitor::CreateWindowMonitor( |
937 ManagePasswordsBubbleView::WebContentMouseHandler::~WebContentMouseHandler() { | 935 this, web_contents->GetTopLevelNativeWindow()); |
938 if (aura::Window* window = GetWebContentsWindow()) | |
939 window->RemovePreTargetHandler(this); | |
940 } | 936 } |
941 | 937 |
942 void ManagePasswordsBubbleView::WebContentMouseHandler::OnKeyEvent( | 938 void ManagePasswordsBubbleView::WebContentMouseHandler::OnKeyEvent( |
943 ui::KeyEvent* event) { | 939 ui::KeyEvent* event) { |
944 content::WebContents* web_contents = bubble_->model()->web_contents(); | 940 content::WebContents* web_contents = bubble_->web_contents(); |
945 content::RenderViewHost* rvh = web_contents->GetRenderViewHost(); | 941 content::RenderViewHost* rvh = web_contents->GetRenderViewHost(); |
946 if (rvh->IsFocusedElementEditable() && | 942 if (rvh->IsFocusedElementEditable() && |
947 event->type() == ui::ET_KEY_PRESSED) | 943 event->type() == ui::ET_KEY_PRESSED) |
948 bubble_->Close(); | 944 bubble_->Close(); |
949 } | 945 } |
950 | 946 |
951 void ManagePasswordsBubbleView::WebContentMouseHandler::OnMouseEvent( | 947 void ManagePasswordsBubbleView::WebContentMouseHandler::OnMouseEvent( |
952 ui::MouseEvent* event) { | 948 ui::MouseEvent* event) { |
953 if (event->type() == ui::ET_MOUSE_PRESSED) | 949 if (event->type() == ui::ET_MOUSE_PRESSED) |
954 bubble_->Close(); | 950 bubble_->Close(); |
955 } | 951 } |
956 | 952 |
957 aura::Window* | |
958 ManagePasswordsBubbleView::WebContentMouseHandler::GetWebContentsWindow() { | |
959 content::WebContents* web_contents = bubble_->model()->web_contents(); | |
960 return web_contents ? web_contents->GetNativeView() : NULL; | |
961 } | |
962 | |
963 // ManagePasswordsBubbleView -------------------------------------------------- | 953 // ManagePasswordsBubbleView -------------------------------------------------- |
964 | 954 |
965 // static | 955 // static |
966 ManagePasswordsBubbleView* ManagePasswordsBubbleView::manage_passwords_bubble_ = | 956 ManagePasswordsBubbleView* ManagePasswordsBubbleView::manage_passwords_bubble_ = |
967 NULL; | 957 NULL; |
968 | 958 |
969 // static | 959 // static |
970 void ManagePasswordsBubbleView::ShowBubble(content::WebContents* web_contents, | 960 void ManagePasswordsBubbleView::ShowBubble(content::WebContents* web_contents, |
971 DisplayReason reason) { | 961 DisplayReason reason) { |
972 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); | 962 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); |
973 DCHECK(browser); | 963 DCHECK(browser); |
974 DCHECK(browser->window()); | 964 DCHECK(browser->window()); |
975 DCHECK(browser->fullscreen_controller()); | 965 DCHECK(browser->fullscreen_controller()); |
976 | 966 |
977 if (IsShowing()) | 967 if (IsShowing()) |
978 return; | 968 return; |
979 | 969 |
980 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser); | 970 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser); |
981 bool is_fullscreen = browser_view->IsFullscreen(); | 971 bool is_fullscreen = browser_view->IsFullscreen(); |
982 ManagePasswordsIconView* anchor_view = | 972 ManagePasswordsIconView* anchor_view = |
983 is_fullscreen | 973 is_fullscreen |
984 ? NULL | 974 ? NULL |
985 : browser_view->GetLocationBarView()->manage_passwords_icon_view(); | 975 : browser_view->GetLocationBarView()->manage_passwords_icon_view(); |
986 manage_passwords_bubble_ = new ManagePasswordsBubbleView( | 976 manage_passwords_bubble_ = new ManagePasswordsBubbleView( |
987 web_contents, anchor_view, reason); | 977 web_contents, anchor_view, reason); |
988 | 978 |
989 if (is_fullscreen) { | 979 if (is_fullscreen) |
990 manage_passwords_bubble_->set_parent_window( | 980 manage_passwords_bubble_->set_parent_window(web_contents->GetNativeView()); |
991 web_contents->GetTopLevelNativeWindow()); | |
992 } | |
993 | 981 |
994 views::BubbleDelegateView::CreateBubble(manage_passwords_bubble_); | 982 views::BubbleDelegateView::CreateBubble(manage_passwords_bubble_); |
995 | 983 |
996 // Adjust for fullscreen after creation as it relies on the content size. | 984 // Adjust for fullscreen after creation as it relies on the content size. |
997 if (is_fullscreen) { | 985 if (is_fullscreen) { |
998 manage_passwords_bubble_->AdjustForFullscreen( | 986 manage_passwords_bubble_->AdjustForFullscreen( |
999 browser_view->GetBoundsInScreen()); | 987 browser_view->GetBoundsInScreen()); |
1000 } | 988 } |
1001 if (reason == AUTOMATIC) | 989 if (reason == AUTOMATIC) |
1002 manage_passwords_bubble_->GetWidget()->ShowInactive(); | 990 manage_passwords_bubble_->GetWidget()->ShowInactive(); |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1144 } | 1132 } |
1145 | 1133 |
1146 void ManagePasswordsBubbleView::Observe( | 1134 void ManagePasswordsBubbleView::Observe( |
1147 int type, | 1135 int type, |
1148 const content::NotificationSource& source, | 1136 const content::NotificationSource& source, |
1149 const content::NotificationDetails& details) { | 1137 const content::NotificationDetails& details) { |
1150 DCHECK_EQ(type, chrome::NOTIFICATION_FULLSCREEN_CHANGED); | 1138 DCHECK_EQ(type, chrome::NOTIFICATION_FULLSCREEN_CHANGED); |
1151 GetWidget()->SetVisibilityAnimationTransition(views::Widget::ANIMATE_NONE); | 1139 GetWidget()->SetVisibilityAnimationTransition(views::Widget::ANIMATE_NONE); |
1152 CloseBubble(); | 1140 CloseBubble(); |
1153 } | 1141 } |
OLD | NEW |