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

Side by Side Diff: chrome/browser/ui/views/passwords/manage_passwords_bubble_view.cc

Issue 730833006: MacViews: Implement event monitoring for a specific window (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 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
OLDNEW
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 763 matching lines...) Expand 10 before | Expand all | Expand 10 after
808 } 808 }
809 809
810 // ManagePasswordsBubbleView::WebContentMouseHandler -------------------------- 810 // ManagePasswordsBubbleView::WebContentMouseHandler --------------------------
811 811
812 // The class listens for WebContentsView events and notifies the bubble if the 812 // The class listens for WebContentsView events and notifies the bubble if the
813 // view was clicked on or received keystrokes. 813 // view was clicked on or received keystrokes.
814 class ManagePasswordsBubbleView::WebContentMouseHandler 814 class ManagePasswordsBubbleView::WebContentMouseHandler
815 : public ui::EventHandler { 815 : public ui::EventHandler {
816 public: 816 public:
817 explicit WebContentMouseHandler(ManagePasswordsBubbleView* bubble); 817 explicit WebContentMouseHandler(ManagePasswordsBubbleView* bubble);
818 ~WebContentMouseHandler() override;
819 818
820 void OnKeyEvent(ui::KeyEvent* event) override; 819 void OnKeyEvent(ui::KeyEvent* event) override;
821 void OnMouseEvent(ui::MouseEvent* event) override; 820 void OnMouseEvent(ui::MouseEvent* event) override;
822 821
823 private: 822 private:
824 aura::Window* GetWebContentsWindow();
825
826 ManagePasswordsBubbleView* bubble_; 823 ManagePasswordsBubbleView* bubble_;
824 scoped_ptr<views::EventMonitor> event_monitor_;
827 825
828 DISALLOW_COPY_AND_ASSIGN(WebContentMouseHandler); 826 DISALLOW_COPY_AND_ASSIGN(WebContentMouseHandler);
829 }; 827 };
830 828
831 ManagePasswordsBubbleView::WebContentMouseHandler::WebContentMouseHandler( 829 ManagePasswordsBubbleView::WebContentMouseHandler::WebContentMouseHandler(
832 ManagePasswordsBubbleView* bubble) 830 ManagePasswordsBubbleView* bubble)
833 : bubble_(bubble) { 831 : bubble_(bubble) {
834 GetWebContentsWindow()->AddPreTargetHandler(this); 832 content::WebContents* web_contents = bubble_->web_contents();
835 } 833 if (web_contents) {
836 834 gfx::NativeWindow target_window = web_contents->GetTopLevelNativeWindow();
837 ManagePasswordsBubbleView::WebContentMouseHandler::~WebContentMouseHandler() { 835 event_monitor_ =
838 if (aura::Window* window = GetWebContentsWindow()) 836 views::EventMonitor::CreateWindowMonitor(this, target_window);
839 window->RemovePreTargetHandler(this); 837 }
840 } 838 }
841 839
842 void ManagePasswordsBubbleView::WebContentMouseHandler::OnKeyEvent( 840 void ManagePasswordsBubbleView::WebContentMouseHandler::OnKeyEvent(
843 ui::KeyEvent* event) { 841 ui::KeyEvent* event) {
844 content::WebContents* web_contents = bubble_->model()->web_contents(); 842 content::WebContents* web_contents = bubble_->web_contents();
845 content::RenderViewHost* rvh = web_contents->GetRenderViewHost(); 843 content::RenderViewHost* rvh = web_contents->GetRenderViewHost();
846 if (rvh->IsFocusedElementEditable() && 844 if (rvh->IsFocusedElementEditable() &&
847 event->type() == ui::ET_KEY_PRESSED) 845 event->type() == ui::ET_KEY_PRESSED)
848 bubble_->Close(); 846 bubble_->Close();
849 } 847 }
850 848
851 void ManagePasswordsBubbleView::WebContentMouseHandler::OnMouseEvent( 849 void ManagePasswordsBubbleView::WebContentMouseHandler::OnMouseEvent(
852 ui::MouseEvent* event) { 850 ui::MouseEvent* event) {
853 if (event->type() == ui::ET_MOUSE_PRESSED) 851 if (event->type() == ui::ET_MOUSE_PRESSED)
854 bubble_->Close(); 852 bubble_->Close();
855 } 853 }
856 854
857 aura::Window*
858 ManagePasswordsBubbleView::WebContentMouseHandler::GetWebContentsWindow() {
859 content::WebContents* web_contents = bubble_->model()->web_contents();
860 return web_contents ? web_contents->GetNativeView() : NULL;
861 }
862
863 // ManagePasswordsBubbleView -------------------------------------------------- 855 // ManagePasswordsBubbleView --------------------------------------------------
864 856
865 // static 857 // static
866 ManagePasswordsBubbleView* ManagePasswordsBubbleView::manage_passwords_bubble_ = 858 ManagePasswordsBubbleView* ManagePasswordsBubbleView::manage_passwords_bubble_ =
867 NULL; 859 NULL;
868 860
869 // static 861 // static
870 void ManagePasswordsBubbleView::ShowBubble(content::WebContents* web_contents, 862 void ManagePasswordsBubbleView::ShowBubble(content::WebContents* web_contents,
871 DisplayReason reason) { 863 DisplayReason reason) {
872 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); 864 Browser* browser = chrome::FindBrowserWithWebContents(web_contents);
873 DCHECK(browser); 865 DCHECK(browser);
874 DCHECK(browser->window()); 866 DCHECK(browser->window());
875 DCHECK(browser->fullscreen_controller()); 867 DCHECK(browser->fullscreen_controller());
876 868
877 if (IsShowing()) 869 if (IsShowing())
878 return; 870 return;
879 871
880 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser); 872 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser);
881 bool is_fullscreen = browser_view->IsFullscreen(); 873 bool is_fullscreen = browser_view->IsFullscreen();
882 ManagePasswordsIconView* anchor_view = 874 ManagePasswordsIconView* anchor_view =
883 is_fullscreen 875 is_fullscreen
884 ? NULL 876 ? NULL
885 : browser_view->GetLocationBarView()->manage_passwords_icon_view(); 877 : browser_view->GetLocationBarView()->manage_passwords_icon_view();
886 manage_passwords_bubble_ = new ManagePasswordsBubbleView( 878 manage_passwords_bubble_ = new ManagePasswordsBubbleView(
887 web_contents, anchor_view, reason); 879 web_contents, anchor_view, reason);
888 880
889 if (is_fullscreen) { 881 if (is_fullscreen)
890 manage_passwords_bubble_->set_parent_window( 882 manage_passwords_bubble_->set_parent_window(web_contents->GetNativeView());
891 web_contents->GetTopLevelNativeWindow());
892 }
893 883
894 views::BubbleDelegateView::CreateBubble(manage_passwords_bubble_); 884 views::BubbleDelegateView::CreateBubble(manage_passwords_bubble_);
895 885
896 // Adjust for fullscreen after creation as it relies on the content size. 886 // Adjust for fullscreen after creation as it relies on the content size.
897 if (is_fullscreen) { 887 if (is_fullscreen) {
898 manage_passwords_bubble_->AdjustForFullscreen( 888 manage_passwords_bubble_->AdjustForFullscreen(
899 browser_view->GetBoundsInScreen()); 889 browser_view->GetBoundsInScreen());
900 } 890 }
901 if (reason == AUTOMATIC) 891 if (reason == AUTOMATIC)
902 manage_passwords_bubble_->GetWidget()->ShowInactive(); 892 manage_passwords_bubble_->GetWidget()->ShowInactive();
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
1037 } 1027 }
1038 1028
1039 void ManagePasswordsBubbleView::Observe( 1029 void ManagePasswordsBubbleView::Observe(
1040 int type, 1030 int type,
1041 const content::NotificationSource& source, 1031 const content::NotificationSource& source,
1042 const content::NotificationDetails& details) { 1032 const content::NotificationDetails& details) {
1043 DCHECK_EQ(type, chrome::NOTIFICATION_FULLSCREEN_CHANGED); 1033 DCHECK_EQ(type, chrome::NOTIFICATION_FULLSCREEN_CHANGED);
1044 GetWidget()->SetVisibilityAnimationTransition(views::Widget::ANIMATE_NONE); 1034 GetWidget()->SetVisibilityAnimationTransition(views::Widget::ANIMATE_NONE);
1045 CloseBubble(); 1035 CloseBubble();
1046 } 1036 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698