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

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, 1 month 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_item_view.h" 17 #include "chrome/browser/ui/views/passwords/manage_password_item_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/styled_label.h" 31 #include "ui/views/controls/styled_label.h"
33 #include "ui/views/controls/styled_label_listener.h" 32 #include "ui/views/controls/styled_label_listener.h"
33 #include "ui/views/event_monitor.h"
34 #include "ui/views/layout/fill_layout.h" 34 #include "ui/views/layout/fill_layout.h"
35 #include "ui/views/layout/grid_layout.h" 35 #include "ui/views/layout/grid_layout.h"
36 #include "ui/views/layout/layout_constants.h" 36 #include "ui/views/layout/layout_constants.h"
37 #include "ui/views/widget/widget.h" 37 #include "ui/views/widget/widget.h"
38 38
39 39
40 // Helpers -------------------------------------------------------------------- 40 // Helpers --------------------------------------------------------------------
41 41
42 namespace { 42 namespace {
43 43
(...skipping 663 matching lines...) Expand 10 before | Expand all | Expand 10 after
707 } 707 }
708 708
709 // ManagePasswordsBubbleView::WebContentMouseHandler -------------------------- 709 // ManagePasswordsBubbleView::WebContentMouseHandler --------------------------
710 710
711 // The class listens for WebContentsView events and notifies the bubble if the 711 // The class listens for WebContentsView events and notifies the bubble if the
712 // view was clicked on or received keystrokes. 712 // view was clicked on or received keystrokes.
713 class ManagePasswordsBubbleView::WebContentMouseHandler 713 class ManagePasswordsBubbleView::WebContentMouseHandler
714 : public ui::EventHandler { 714 : public ui::EventHandler {
715 public: 715 public:
716 explicit WebContentMouseHandler(ManagePasswordsBubbleView* bubble); 716 explicit WebContentMouseHandler(ManagePasswordsBubbleView* bubble);
717 ~WebContentMouseHandler() override;
718 717
719 void OnKeyEvent(ui::KeyEvent* event) override; 718 void OnKeyEvent(ui::KeyEvent* event) override;
720 void OnMouseEvent(ui::MouseEvent* event) override; 719 void OnMouseEvent(ui::MouseEvent* event) override;
721 720
722 private: 721 private:
723 aura::Window* GetWebContentsWindow();
724
725 ManagePasswordsBubbleView* bubble_; 722 ManagePasswordsBubbleView* bubble_;
723 scoped_ptr<views::EventMonitor> event_monitor_;
726 724
727 DISALLOW_COPY_AND_ASSIGN(WebContentMouseHandler); 725 DISALLOW_COPY_AND_ASSIGN(WebContentMouseHandler);
728 }; 726 };
729 727
730 ManagePasswordsBubbleView::WebContentMouseHandler::WebContentMouseHandler( 728 ManagePasswordsBubbleView::WebContentMouseHandler::WebContentMouseHandler(
731 ManagePasswordsBubbleView* bubble) 729 ManagePasswordsBubbleView* bubble)
732 : bubble_(bubble) { 730 : bubble_(bubble) {
733 GetWebContentsWindow()->AddPreTargetHandler(this); 731 content::WebContents* web_contents = bubble_->web_contents();
734 } 732 if (web_contents) {
735 733 gfx::NativeWindow target_window = web_contents->GetTopLevelNativeWindow();
736 ManagePasswordsBubbleView::WebContentMouseHandler::~WebContentMouseHandler() { 734 event_monitor_.reset(views::EventMonitor::Create(this, target_window));
tapted 2014/11/21 00:57:34 can you make the views::EventMonitor::Create* retu
Andre 2014/12/10 00:18:13 Done.
737 if (aura::Window* window = GetWebContentsWindow()) 735 }
738 window->RemovePreTargetHandler(this);
739 } 736 }
740 737
741 void ManagePasswordsBubbleView::WebContentMouseHandler::OnKeyEvent( 738 void ManagePasswordsBubbleView::WebContentMouseHandler::OnKeyEvent(
742 ui::KeyEvent* event) { 739 ui::KeyEvent* event) {
743 content::WebContents* web_contents = bubble_->model()->web_contents(); 740 content::WebContents* web_contents = bubble_->web_contents();
744 content::RenderViewHost* rvh = web_contents->GetRenderViewHost(); 741 content::RenderViewHost* rvh = web_contents->GetRenderViewHost();
745 if (rvh->IsFocusedElementEditable() && 742 if (rvh->IsFocusedElementEditable() &&
746 event->type() == ui::ET_KEY_PRESSED) 743 event->type() == ui::ET_KEY_PRESSED)
747 bubble_->Close(); 744 bubble_->Close();
748 } 745 }
749 746
750 void ManagePasswordsBubbleView::WebContentMouseHandler::OnMouseEvent( 747 void ManagePasswordsBubbleView::WebContentMouseHandler::OnMouseEvent(
751 ui::MouseEvent* event) { 748 ui::MouseEvent* event) {
752 if (event->type() == ui::ET_MOUSE_PRESSED) 749 if (event->type() == ui::ET_MOUSE_PRESSED)
753 bubble_->Close(); 750 bubble_->Close();
754 } 751 }
755 752
756 aura::Window*
757 ManagePasswordsBubbleView::WebContentMouseHandler::GetWebContentsWindow() {
758 content::WebContents* web_contents = bubble_->model()->web_contents();
759 return web_contents ? web_contents->GetNativeView() : NULL;
760 }
761
762 // ManagePasswordsBubbleView -------------------------------------------------- 753 // ManagePasswordsBubbleView --------------------------------------------------
763 754
764 // static 755 // static
765 ManagePasswordsBubbleView* ManagePasswordsBubbleView::manage_passwords_bubble_ = 756 ManagePasswordsBubbleView* ManagePasswordsBubbleView::manage_passwords_bubble_ =
766 NULL; 757 NULL;
767 758
768 // static 759 // static
769 void ManagePasswordsBubbleView::ShowBubble(content::WebContents* web_contents, 760 void ManagePasswordsBubbleView::ShowBubble(content::WebContents* web_contents,
770 DisplayReason reason) { 761 DisplayReason reason) {
771 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); 762 Browser* browser = chrome::FindBrowserWithWebContents(web_contents);
772 DCHECK(browser); 763 DCHECK(browser);
773 DCHECK(browser->window()); 764 DCHECK(browser->window());
774 DCHECK(browser->fullscreen_controller()); 765 DCHECK(browser->fullscreen_controller());
775 766
776 if (IsShowing()) 767 if (IsShowing())
777 return; 768 return;
778 769
779 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser); 770 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser);
780 bool is_fullscreen = browser_view->IsFullscreen(); 771 bool is_fullscreen = browser_view->IsFullscreen();
781 ManagePasswordsIconView* anchor_view = 772 ManagePasswordsIconView* anchor_view =
782 is_fullscreen 773 is_fullscreen
783 ? NULL 774 ? NULL
784 : browser_view->GetLocationBarView()->manage_passwords_icon_view(); 775 : browser_view->GetLocationBarView()->manage_passwords_icon_view();
785 manage_passwords_bubble_ = new ManagePasswordsBubbleView( 776 manage_passwords_bubble_ = new ManagePasswordsBubbleView(
786 web_contents, anchor_view, reason); 777 web_contents, anchor_view, reason);
787 778
788 if (is_fullscreen) { 779 if (is_fullscreen) {
tapted 2014/11/20 22:39:02 nit: no curlies
Andre 2014/12/10 00:18:13 Done.
789 manage_passwords_bubble_->set_parent_window( 780 manage_passwords_bubble_->set_parent_window(web_contents->GetNativeView());
790 web_contents->GetTopLevelNativeWindow());
791 } 781 }
792 782
793 views::BubbleDelegateView::CreateBubble(manage_passwords_bubble_); 783 views::BubbleDelegateView::CreateBubble(manage_passwords_bubble_);
794 784
795 // Adjust for fullscreen after creation as it relies on the content size. 785 // Adjust for fullscreen after creation as it relies on the content size.
796 if (is_fullscreen) { 786 if (is_fullscreen) {
797 manage_passwords_bubble_->AdjustForFullscreen( 787 manage_passwords_bubble_->AdjustForFullscreen(
798 browser_view->GetBoundsInScreen()); 788 browser_view->GetBoundsInScreen());
799 } 789 }
800 if (reason == AUTOMATIC) 790 if (reason == AUTOMATIC)
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
933 } 923 }
934 924
935 void ManagePasswordsBubbleView::Observe( 925 void ManagePasswordsBubbleView::Observe(
936 int type, 926 int type,
937 const content::NotificationSource& source, 927 const content::NotificationSource& source,
938 const content::NotificationDetails& details) { 928 const content::NotificationDetails& details) {
939 DCHECK_EQ(type, chrome::NOTIFICATION_FULLSCREEN_CHANGED); 929 DCHECK_EQ(type, chrome::NOTIFICATION_FULLSCREEN_CHANGED);
940 GetWidget()->SetVisibilityAnimationTransition(views::Widget::ANIMATE_NONE); 930 GetWidget()->SetVisibilityAnimationTransition(views::Widget::ANIMATE_NONE);
941 CloseBubble(); 931 CloseBubble();
942 } 932 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698