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

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: Fixes for sky 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 775 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 DCHECK(web_contents);
848 846 event_monitor_ = views::EventMonitor::CreateWindowMonitor(
849 ManagePasswordsBubbleView::WebContentMouseHandler::~WebContentMouseHandler() { 847 this, web_contents->GetTopLevelNativeWindow());
850 if (aura::Window* window = GetWebContentsWindow())
851 window->RemovePreTargetHandler(this);
852 } 848 }
853 849
854 void ManagePasswordsBubbleView::WebContentMouseHandler::OnKeyEvent( 850 void ManagePasswordsBubbleView::WebContentMouseHandler::OnKeyEvent(
855 ui::KeyEvent* event) { 851 ui::KeyEvent* event) {
856 content::WebContents* web_contents = bubble_->model()->web_contents(); 852 content::WebContents* web_contents = bubble_->web_contents();
857 content::RenderViewHost* rvh = web_contents->GetRenderViewHost(); 853 content::RenderViewHost* rvh = web_contents->GetRenderViewHost();
858 if (rvh->IsFocusedElementEditable() && 854 if (rvh->IsFocusedElementEditable() &&
859 event->type() == ui::ET_KEY_PRESSED) 855 event->type() == ui::ET_KEY_PRESSED)
860 bubble_->Close(); 856 bubble_->Close();
861 } 857 }
862 858
863 void ManagePasswordsBubbleView::WebContentMouseHandler::OnMouseEvent( 859 void ManagePasswordsBubbleView::WebContentMouseHandler::OnMouseEvent(
864 ui::MouseEvent* event) { 860 ui::MouseEvent* event) {
865 if (event->type() == ui::ET_MOUSE_PRESSED) 861 if (event->type() == ui::ET_MOUSE_PRESSED)
866 bubble_->Close(); 862 bubble_->Close();
867 } 863 }
868 864
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 -------------------------------------------------- 865 // ManagePasswordsBubbleView --------------------------------------------------
876 866
877 // static 867 // static
878 ManagePasswordsBubbleView* ManagePasswordsBubbleView::manage_passwords_bubble_ = 868 ManagePasswordsBubbleView* ManagePasswordsBubbleView::manage_passwords_bubble_ =
879 NULL; 869 NULL;
880 870
881 // static 871 // static
882 void ManagePasswordsBubbleView::ShowBubble(content::WebContents* web_contents, 872 void ManagePasswordsBubbleView::ShowBubble(content::WebContents* web_contents,
883 DisplayReason reason) { 873 DisplayReason reason) {
884 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); 874 Browser* browser = chrome::FindBrowserWithWebContents(web_contents);
885 DCHECK(browser); 875 DCHECK(browser);
886 DCHECK(browser->window()); 876 DCHECK(browser->window());
887 DCHECK(browser->fullscreen_controller()); 877 DCHECK(browser->fullscreen_controller());
888 878
889 if (IsShowing()) 879 if (IsShowing())
890 return; 880 return;
891 881
892 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser); 882 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser);
893 bool is_fullscreen = browser_view->IsFullscreen(); 883 bool is_fullscreen = browser_view->IsFullscreen();
894 ManagePasswordsIconView* anchor_view = 884 ManagePasswordsIconView* anchor_view =
895 is_fullscreen 885 is_fullscreen
896 ? NULL 886 ? NULL
897 : browser_view->GetLocationBarView()->manage_passwords_icon_view(); 887 : browser_view->GetLocationBarView()->manage_passwords_icon_view();
898 manage_passwords_bubble_ = new ManagePasswordsBubbleView( 888 manage_passwords_bubble_ = new ManagePasswordsBubbleView(
899 web_contents, anchor_view, reason); 889 web_contents, anchor_view, reason);
900 890
901 if (is_fullscreen) { 891 if (is_fullscreen)
902 manage_passwords_bubble_->set_parent_window( 892 manage_passwords_bubble_->set_parent_window(web_contents->GetNativeView());
903 web_contents->GetTopLevelNativeWindow());
904 }
905 893
906 views::BubbleDelegateView::CreateBubble(manage_passwords_bubble_); 894 views::BubbleDelegateView::CreateBubble(manage_passwords_bubble_);
907 895
908 // Adjust for fullscreen after creation as it relies on the content size. 896 // Adjust for fullscreen after creation as it relies on the content size.
909 if (is_fullscreen) { 897 if (is_fullscreen) {
910 manage_passwords_bubble_->AdjustForFullscreen( 898 manage_passwords_bubble_->AdjustForFullscreen(
911 browser_view->GetBoundsInScreen()); 899 browser_view->GetBoundsInScreen());
912 } 900 }
913 if (reason == AUTOMATIC) 901 if (reason == AUTOMATIC)
914 manage_passwords_bubble_->GetWidget()->ShowInactive(); 902 manage_passwords_bubble_->GetWidget()->ShowInactive();
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
1049 } 1037 }
1050 1038
1051 void ManagePasswordsBubbleView::Observe( 1039 void ManagePasswordsBubbleView::Observe(
1052 int type, 1040 int type,
1053 const content::NotificationSource& source, 1041 const content::NotificationSource& source,
1054 const content::NotificationDetails& details) { 1042 const content::NotificationDetails& details) {
1055 DCHECK_EQ(type, chrome::NOTIFICATION_FULLSCREEN_CHANGED); 1043 DCHECK_EQ(type, chrome::NOTIFICATION_FULLSCREEN_CHANGED);
1056 GetWidget()->SetVisibilityAnimationTransition(views::Widget::ANIMATE_NONE); 1044 GetWidget()->SetVisibilityAnimationTransition(views::Widget::ANIMATE_NONE);
1057 CloseBubble(); 1045 CloseBubble();
1058 } 1046 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/location_bar/zoom_bubble_view.cc ('k') | chrome/browser/ui/views/status_bubble_views.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698