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 775 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
820 } | 820 } |
821 | 821 |
822 // ManagePasswordsBubbleView::WebContentMouseHandler -------------------------- | 822 // ManagePasswordsBubbleView::WebContentMouseHandler -------------------------- |
823 | 823 |
824 // The class listens for WebContentsView events and notifies the bubble if the | 824 // The class listens for WebContentsView events and notifies the bubble if the |
825 // view was clicked on or received keystrokes. | 825 // view was clicked on or received keystrokes. |
826 class ManagePasswordsBubbleView::WebContentMouseHandler | 826 class ManagePasswordsBubbleView::WebContentMouseHandler |
827 : public ui::EventHandler { | 827 : public ui::EventHandler { |
828 public: | 828 public: |
829 explicit WebContentMouseHandler(ManagePasswordsBubbleView* bubble); | 829 explicit WebContentMouseHandler(ManagePasswordsBubbleView* bubble); |
830 ~WebContentMouseHandler() override; | |
831 | 830 |
832 void OnKeyEvent(ui::KeyEvent* event) override; | 831 void OnKeyEvent(ui::KeyEvent* event) override; |
833 void OnMouseEvent(ui::MouseEvent* event) override; | 832 void OnMouseEvent(ui::MouseEvent* event) override; |
834 | 833 |
835 private: | 834 private: |
836 aura::Window* GetWebContentsWindow(); | |
837 | |
838 ManagePasswordsBubbleView* bubble_; | 835 ManagePasswordsBubbleView* bubble_; |
836 scoped_ptr<views::EventMonitor> event_monitor_; | |
839 | 837 |
840 DISALLOW_COPY_AND_ASSIGN(WebContentMouseHandler); | 838 DISALLOW_COPY_AND_ASSIGN(WebContentMouseHandler); |
841 }; | 839 }; |
842 | 840 |
843 ManagePasswordsBubbleView::WebContentMouseHandler::WebContentMouseHandler( | 841 ManagePasswordsBubbleView::WebContentMouseHandler::WebContentMouseHandler( |
844 ManagePasswordsBubbleView* bubble) | 842 ManagePasswordsBubbleView* bubble) |
845 : bubble_(bubble) { | 843 : bubble_(bubble) { |
846 GetWebContentsWindow()->AddPreTargetHandler(this); | 844 content::WebContents* web_contents = bubble_->web_contents(); |
847 } | 845 if (web_contents) { |
sky
2014/12/11 00:49:43
Should this be a DCHECK? Without a webcontents won
Andre
2014/12/11 18:09:11
Done.
I also removed the local variable target_win
| |
848 | 846 gfx::NativeWindow target_window = web_contents->GetTopLevelNativeWindow(); |
849 ManagePasswordsBubbleView::WebContentMouseHandler::~WebContentMouseHandler() { | 847 event_monitor_ = |
850 if (aura::Window* window = GetWebContentsWindow()) | 848 views::EventMonitor::CreateWindowMonitor(this, target_window); |
851 window->RemovePreTargetHandler(this); | 849 } |
852 } | 850 } |
853 | 851 |
854 void ManagePasswordsBubbleView::WebContentMouseHandler::OnKeyEvent( | 852 void ManagePasswordsBubbleView::WebContentMouseHandler::OnKeyEvent( |
855 ui::KeyEvent* event) { | 853 ui::KeyEvent* event) { |
856 content::WebContents* web_contents = bubble_->model()->web_contents(); | 854 content::WebContents* web_contents = bubble_->web_contents(); |
857 content::RenderViewHost* rvh = web_contents->GetRenderViewHost(); | 855 content::RenderViewHost* rvh = web_contents->GetRenderViewHost(); |
858 if (rvh->IsFocusedElementEditable() && | 856 if (rvh->IsFocusedElementEditable() && |
859 event->type() == ui::ET_KEY_PRESSED) | 857 event->type() == ui::ET_KEY_PRESSED) |
860 bubble_->Close(); | 858 bubble_->Close(); |
861 } | 859 } |
862 | 860 |
863 void ManagePasswordsBubbleView::WebContentMouseHandler::OnMouseEvent( | 861 void ManagePasswordsBubbleView::WebContentMouseHandler::OnMouseEvent( |
864 ui::MouseEvent* event) { | 862 ui::MouseEvent* event) { |
865 if (event->type() == ui::ET_MOUSE_PRESSED) | 863 if (event->type() == ui::ET_MOUSE_PRESSED) |
866 bubble_->Close(); | 864 bubble_->Close(); |
867 } | 865 } |
868 | 866 |
869 aura::Window* | |
870 ManagePasswordsBubbleView::WebContentMouseHandler::GetWebContentsWindow() { | |
871 content::WebContents* web_contents = bubble_->model()->web_contents(); | |
872 return web_contents ? web_contents->GetNativeView() : NULL; | |
873 } | |
874 | |
875 // ManagePasswordsBubbleView -------------------------------------------------- | 867 // ManagePasswordsBubbleView -------------------------------------------------- |
876 | 868 |
877 // static | 869 // static |
878 ManagePasswordsBubbleView* ManagePasswordsBubbleView::manage_passwords_bubble_ = | 870 ManagePasswordsBubbleView* ManagePasswordsBubbleView::manage_passwords_bubble_ = |
879 NULL; | 871 NULL; |
880 | 872 |
881 // static | 873 // static |
882 void ManagePasswordsBubbleView::ShowBubble(content::WebContents* web_contents, | 874 void ManagePasswordsBubbleView::ShowBubble(content::WebContents* web_contents, |
883 DisplayReason reason) { | 875 DisplayReason reason) { |
884 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); | 876 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); |
885 DCHECK(browser); | 877 DCHECK(browser); |
886 DCHECK(browser->window()); | 878 DCHECK(browser->window()); |
887 DCHECK(browser->fullscreen_controller()); | 879 DCHECK(browser->fullscreen_controller()); |
888 | 880 |
889 if (IsShowing()) | 881 if (IsShowing()) |
890 return; | 882 return; |
891 | 883 |
892 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser); | 884 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser); |
893 bool is_fullscreen = browser_view->IsFullscreen(); | 885 bool is_fullscreen = browser_view->IsFullscreen(); |
894 ManagePasswordsIconView* anchor_view = | 886 ManagePasswordsIconView* anchor_view = |
895 is_fullscreen | 887 is_fullscreen |
896 ? NULL | 888 ? NULL |
897 : browser_view->GetLocationBarView()->manage_passwords_icon_view(); | 889 : browser_view->GetLocationBarView()->manage_passwords_icon_view(); |
898 manage_passwords_bubble_ = new ManagePasswordsBubbleView( | 890 manage_passwords_bubble_ = new ManagePasswordsBubbleView( |
899 web_contents, anchor_view, reason); | 891 web_contents, anchor_view, reason); |
900 | 892 |
901 if (is_fullscreen) { | 893 if (is_fullscreen) |
902 manage_passwords_bubble_->set_parent_window( | 894 manage_passwords_bubble_->set_parent_window(web_contents->GetNativeView()); |
903 web_contents->GetTopLevelNativeWindow()); | |
904 } | |
905 | 895 |
906 views::BubbleDelegateView::CreateBubble(manage_passwords_bubble_); | 896 views::BubbleDelegateView::CreateBubble(manage_passwords_bubble_); |
907 | 897 |
908 // Adjust for fullscreen after creation as it relies on the content size. | 898 // Adjust for fullscreen after creation as it relies on the content size. |
909 if (is_fullscreen) { | 899 if (is_fullscreen) { |
910 manage_passwords_bubble_->AdjustForFullscreen( | 900 manage_passwords_bubble_->AdjustForFullscreen( |
911 browser_view->GetBoundsInScreen()); | 901 browser_view->GetBoundsInScreen()); |
912 } | 902 } |
913 if (reason == AUTOMATIC) | 903 if (reason == AUTOMATIC) |
914 manage_passwords_bubble_->GetWidget()->ShowInactive(); | 904 manage_passwords_bubble_->GetWidget()->ShowInactive(); |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1049 } | 1039 } |
1050 | 1040 |
1051 void ManagePasswordsBubbleView::Observe( | 1041 void ManagePasswordsBubbleView::Observe( |
1052 int type, | 1042 int type, |
1053 const content::NotificationSource& source, | 1043 const content::NotificationSource& source, |
1054 const content::NotificationDetails& details) { | 1044 const content::NotificationDetails& details) { |
1055 DCHECK_EQ(type, chrome::NOTIFICATION_FULLSCREEN_CHANGED); | 1045 DCHECK_EQ(type, chrome::NOTIFICATION_FULLSCREEN_CHANGED); |
1056 GetWidget()->SetVisibilityAnimationTransition(views::Widget::ANIMATE_NONE); | 1046 GetWidget()->SetVisibilityAnimationTransition(views::Widget::ANIMATE_NONE); |
1057 CloseBubble(); | 1047 CloseBubble(); |
1058 } | 1048 } |
OLD | NEW |